-
Notifications
You must be signed in to change notification settings - Fork 549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
S3 upload MD5 not automatically populated #1236
Comments
Hi @emarc-m To answer your question, the S3 client will automatically set and attach content MD5 hash to object metadata without having to do so manually. Would you be able to provide us with the code snippet you are using to set up your transfer utility object and to upload the file? |
Hi @raphkim. Thanks for following up. This is the Transfer utility initialization code: try {
val latch = CountDownLatch(1)
AWSMobileClient.getInstance().initialize(context,
object : Callback<UserStateDetails> {
override fun onResult(result: UserStateDetails) {
latch.countDown()
}
override fun onError(error: Exception) {
throw error
}
}
)
latch.await()
val mobileClient = AWSMobileClient.getInstance()
val regionString = AWSConfiguration(context)
.optJsonObject("S3TransferUtility")
.getString("Region")
val region = Region.getRegion(regionString)
s3Client = AmazonS3Client(mobileClient, region)
transferUtility = TransferUtility.builder()
.context(context)
.s3Client(s3Client)
.awsConfiguration(AWSConfiguration(context))
.build()
} catch (error: Exception) {
throw IllegalStateException("Unable to initialize FileSync")
error.printStackTrace()
} Here's a code snippet of the usage of the upload API from data class MediaRecord(
val uploaded: Boolean = false,
val hash: String = "",
val size: Int = -1
)
@WorkerThread
private fun uploadMedia(mediaRecord: MediaRecord): MediaRecord {
// Done uploading this media resource
if (mediaRecord.uploaded) {
return mediaRecord
}
val mediaFile = getFileForMedia(mediaRecord)
if (!mediaFile.exists() || !mediaFile.isFile) {
return mediaRecord
}
val latch = CountDownLatch(1)
var isUploaded = false
transferUtility.upload(mediaRecord.hash, mediaFile)
.setTransferListener(object : TransferListener {
override fun onProgressChanged(id: Int, bytesCurrent: Long, bytesTotal: Long) {
Timber.d("Upload update for ${mediaRecord.hash} with ID: $id, current: $bytesCurrent, total: $bytesTotal")
}
override fun onStateChanged(id: Int, state: TransferState?) {
state ?: return
Timber.d("Upload state change for ${mediaRecord.hash} with ID: $id, state: $state")
when (state) {
TransferState.COMPLETED -> {
isUploaded = true
latch.countDown()
}
else -> {
// do nothing
}
}
}
override fun onError(id: Int, error: Exception?) {
Timber.d(error, "Error uploading ${mediaRecord.hash} with ID: $id")
isUploaded = false
latch.countDown()
}
})
latch.await()
return mediaRecord.copy(uploaded = isUploaded)
} |
May I ask your use-case for obtaining MD5? The MD5 hash is attached in the http request header and the integrity of file upload is checked automatically in the backend. |
I'm trying to confirm that the SDK is doing what was stated in the Javadocs to ensure that the MD5 consistency check is actually happening. I wanted to be assured that the file will not be corrupted during transport. I tried checking the existence of the computed MD5 value in the following places:
Is there something I miss with to check? |
Thank you for reporting this issue. I identified the root cause to be that the high level client |
I understand. I can confirm that Will this issue be address in a future version of the SDK? Thank you for looking into this. |
@emarc-m Meanwhile, low level client's I hope this helps. |
Thank you for clarifying. Please feel free to close this once #1240 is merged. |
State your question
I've read the documentation for the MD5 file integrity check when uploading files to S3. Please see: https://aws-amplify.github.io/aws-sdk-android/docs/reference/com/amazonaws/services/s3/model/ObjectMetadata.html#getContentMD5--
It says on the documentation that
However, looking at the database entry for the transfer utility, it does not contain any data about the MD5. Also, checking
UploadTask#createPutObjectRequest L:457
,upload.md5
is null.Does this MD5 header need to be computed and set manually? Thank you.
Which AWS Services are you utilizing?
AWS S3
Provide code snippets (if applicable)
Java docs snippet:
Environment(please complete the following information):
Device Information (please complete the following information):
The text was updated successfully, but these errors were encountered: