Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ByteStream Extension fun does not work as expected #1127

Unanswered
hantsy asked this question in Q&A
Discussion options

I tried to replace my codes using FLow<ByteArray>.toByteStream in my codes, but encountered error like this.

The Github actions stack: https://github.com/hantsy/aws-sdk-kotlin-spring-example/actions/runs/6939132384/job/18875971395?pr=6#step:6:79

The original code caused this issue:

suspend fun S3Client.store(bucketName: String, resourceKey: String, data: Flux<DataBuffer>) {
 this.createBucketIfNotExists(bucketName)
 val mediaType = MediaTypeFactory.getMediaType(resourceKey)
 .orElseGet { MediaType.APPLICATION_OCTET_STREAM }
 val byteArrayFlow = data
 .map { dataBuffer ->
 val bytes = ByteArray(dataBuffer.readableByteCount())
 dataBuffer.read(bytes)
 DataBufferUtils.release(dataBuffer)
 bytes
 }
 .asFlow()
 val request = PutObjectRequest {
 bucket = bucketName
 body = byteArrayFlow.toByteStream(applicationScope) // here I use toByteStream to transfer the data type.
 key = resourceKey
 contentType = mediaType.toString()
 }
 val result = try {
 this.putObject(request)
 } catch (e: Exception) {
 throw S3ClientException(e.message ?: "Failed to store object $resourceKey")
 }
 println("store object to $bucketName: ${result.eTag}")
}
You must be logged in to vote

Replies: 2 comments

Comment options

add to request checksumAlgorithm = ChecksumAlgorithm.Sha256

You must be logged in to vote
0 replies
Comment options

It maybe still related to the Content Length header, in my case, we do not know uploaded file size.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /