Skip to content

Commit

Permalink
Update docs, fix some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert committed Jan 15, 2025
1 parent d78e500 commit fe2b9cf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ sealed interface BucketApi {
*/
const val UPSERT_HEADER = "x-upsert"

/**
* The header to use for the user metadata
*/
const val METADATA_HEADER = "x-metadata"

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import kotlinx.serialization.json.jsonPrimitive
import kotlinx.serialization.json.put
import kotlinx.serialization.json.putJsonArray
import kotlinx.serialization.json.putJsonObject
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
import kotlin.time.Duration

internal class BucketApiImpl(override val bucketId: String, val storage: StorageImpl, resumableCache: ResumableCache) : BucketApi {
Expand Down Expand Up @@ -265,6 +267,7 @@ internal class BucketApiImpl(override val bucketId: String, val storage: Storage
return FileUploadResponse(id, path, key)
}

@OptIn(ExperimentalEncodingApi::class)
private fun HttpRequestBuilder.defaultUploadRequest(
path: String,
data: UploadData,
Expand All @@ -277,6 +280,9 @@ internal class BucketApiImpl(override val bucketId: String, val storage: Storage
})
header(HttpHeaders.ContentType, optionBuilder.contentType ?: ContentType.defaultForFilePath(path))
header(UPSERT_HEADER, optionBuilder.upsert.toString())
optionBuilder.userMetadata?.let {
header(BucketApi.METADATA_HEADER, Base64.encode(it.toString().encodeToByteArray()))
}
}

override suspend fun changePublicStatusTo(public: Boolean) = storage.updateBucket(bucketId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ data class FileObjectV2(
@SerialName("updated_at")
val updatedAt: Instant? = null,
@SerialName("created_at")
val createdAt: Instant?,
val createdAt: Instant,
@SerialName("last_accessed_at")
val lastAccessedAt: Instant? = null,
val metadata: JsonObject?,
val metadata: JsonObject? = null,
val size: Long,
@SerialName("content_type")
val rawContentType: String,
val etag: String?,
val etag: String? = null,
@SerialName("last_modified")
val lastModified: Instant?,
val lastModified: Instant? = null,
@SerialName("cache_control")
val cacheControl: String?,
val cacheControl: String? = null,
@Transient @PublishedApi internal val serializer: SupabaseSerializer = KotlinXSerializer()
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kotlinx.serialization.json.jsonObject
* Builder for uploading files with additional options
* @param serializer The serializer to use for encoding the metadata
* @param upsert Whether to update the file if it already exists
* @param userMetadata The user metadata to upload with the file
* @param contentType The content type of the file. If null, the content type will be inferred from the file extension
*/
class UploadOptionBuilder(
Expand All @@ -24,7 +25,8 @@ class UploadOptionBuilder(
) {

/**
* Overrides the HTTP request
* Adds an [HttpRequestOverride] to the upload request
* @param override The override to add
*/
fun httpOverride(override: HttpRequestOverride) {
httpRequestOverrides.add(override)
Expand Down

0 comments on commit fe2b9cf

Please sign in to comment.