I developed an Android application,where the user can upload a file to the server.
A send the file with multipart data. Althought the api creats the file, but it is corrupted, I can't open it.
If I send the file via postman, the file in the server is good, and I can open it.
I checked the original, and the newly created file, and i noticed that, the new file is bigger than the original with 2 bytes.After that I compared the 2 files byte codes, and if I skip the first 2 byte in the new one, than the 2 byte array are the same.
So why get 2 extra byte the new file?
I created the api function based on this answer: Httplistener and file upload
**Api interface**
@Multipart
@POST("...")
suspend fun saveOrUpdateDocument2(@Query("name") name: String, @Query("extension") extension: String, @Part file: MultipartBody.Part): ResponseBody
**Function:**
context.contentResolver.openInputStream(uri)?.let {
val bytes = it.readBytes()
val requestFile = RequestBody.create(MediaType.parse("*/*"),bytes)
val body = MultipartBody.Part.createFormData("file",documentUploadDto.originalFileName,requestFile)
api.saveOrUpdateDocument2(documentUploadDto.originalFileName,documentUploadDto.extension,body)
}