Search code examples
androidamazon-s3kotlinretrofitretrofit2

AWS S3 file upload with retrofit2 video/image corrupt


When uploading files to s3 using retrofit uploads successfully and returns a 200 however the file is corrupted. The file can be either a video or image.

 val requestFile = RequestBody.create(MediaType.parse(contentType), file)
 val body = MultipartBody.Part.createFormData(mediaType, task.file_name, requestFile)

assetService.uploadAsset(contentType, task.upload_url, body)

where contentType is either "video/mp4" or "image/jpeg" and mediaType is either "video" or "image"

the service :

@Multipart
@PUT
fun uploadAsset(
    @Header(CONTENT_TYPE) contentType: String,
    @Url uploadUrl: String,
    @Part file: MultipartBody.Part
): Single<ResponseBody>

The files upload and look correct however they are corrupt and cannot be viewed.

I've checked this question but still stuck. AWS S3 Rest API with Android Retrofit V2 library, uploaded image is damaged


Solution

  • Removed Multipart upload and it worked.