Better handling of filename

This commit is contained in:
Benoit Marty 2021-05-21 13:22:26 +02:00 committed by Benoit Marty
parent 762eb0db12
commit fb5dda30bd
2 changed files with 22 additions and 11 deletions

View File

@ -121,11 +121,17 @@ internal class FileUploader @Inject constructor(
}
}
private suspend fun upload(uploadBody: RequestBody, filename: String?, progressListener: ProgressRequestBody.Listener?): ContentUploadResponse {
private suspend fun upload(uploadBody: RequestBody,
filename: String?,
progressListener: ProgressRequestBody.Listener?): ContentUploadResponse {
val urlBuilder = uploadUrl.toHttpUrlOrNull()?.newBuilder() ?: throw RuntimeException()
val httpUrl = urlBuilder
.addQueryParameter("filename", filename)
.apply {
if (filename != null) {
addQueryParameter("filename", filename)
}
}
.build()
val requestBody = if (progressListener != null) ProgressRequestBody(uploadBody, progressListener) else uploadBody

View File

@ -229,7 +229,6 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
val encryptedFile: File?
val contentUploadResponse = if (params.isEncrypted) {
Timber.v("## Encrypt file")
encryptedFile = temporaryFileCreator.create()
.also { filesToDelete.add(it) }
@ -239,16 +238,22 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
contentUploadStateTracker.setEncrypting(it, read.toLong(), total.toLong())
}
}
Timber.v("## Uploading file")
fileUploader
.uploadFile(encryptedFile, attachment.name, MimeTypes.OctetStream, progressListener)
fileUploader.uploadFile(
file = encryptedFile,
filename = null,
mimeType = MimeTypes.OctetStream,
progressListener = progressListener
)
} else {
Timber.v("## Clear file")
Timber.v("## Uploading clear file")
encryptedFile = null
fileUploader
.uploadFile(fileToUpload, attachment.name, attachment.getSafeMimeType(), progressListener)
fileUploader.uploadFile(
file = fileToUpload,
filename = attachment.name,
mimeType = attachment.getSafeMimeType(),
progressListener = progressListener
)
}
Timber.v("## Update cache storage for ${contentUploadResponse.contentUri}")
@ -312,7 +317,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
val encryptionResult = MXEncryptedAttachments.encryptAttachment(thumbnailData.bytes.inputStream(), thumbnailData.mimeType)
val contentUploadResponse = fileUploader.uploadByteArray(
byteArray = encryptionResult.encryptedByteArray,
filename = "thumb_${params.attachment.name}",
filename = null,
mimeType = MimeTypes.OctetStream,
progressListener = thumbnailProgressListener
)