Better handling of filename
This commit is contained in:
parent
762eb0db12
commit
fb5dda30bd
@ -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 urlBuilder = uploadUrl.toHttpUrlOrNull()?.newBuilder() ?: throw RuntimeException()
|
||||||
|
|
||||||
val httpUrl = urlBuilder
|
val httpUrl = urlBuilder
|
||||||
.addQueryParameter("filename", filename)
|
.apply {
|
||||||
|
if (filename != null) {
|
||||||
|
addQueryParameter("filename", filename)
|
||||||
|
}
|
||||||
|
}
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val requestBody = if (progressListener != null) ProgressRequestBody(uploadBody, progressListener) else uploadBody
|
val requestBody = if (progressListener != null) ProgressRequestBody(uploadBody, progressListener) else uploadBody
|
||||||
|
@ -229,7 +229,6 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
|
|||||||
val encryptedFile: File?
|
val encryptedFile: File?
|
||||||
val contentUploadResponse = if (params.isEncrypted) {
|
val contentUploadResponse = if (params.isEncrypted) {
|
||||||
Timber.v("## Encrypt file")
|
Timber.v("## Encrypt file")
|
||||||
|
|
||||||
encryptedFile = temporaryFileCreator.create()
|
encryptedFile = temporaryFileCreator.create()
|
||||||
.also { filesToDelete.add(it) }
|
.also { filesToDelete.add(it) }
|
||||||
|
|
||||||
@ -239,16 +238,22 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
|
|||||||
contentUploadStateTracker.setEncrypting(it, read.toLong(), total.toLong())
|
contentUploadStateTracker.setEncrypting(it, read.toLong(), total.toLong())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Timber.v("## Uploading file")
|
Timber.v("## Uploading file")
|
||||||
|
fileUploader.uploadFile(
|
||||||
fileUploader
|
file = encryptedFile,
|
||||||
.uploadFile(encryptedFile, attachment.name, MimeTypes.OctetStream, progressListener)
|
filename = null,
|
||||||
|
mimeType = MimeTypes.OctetStream,
|
||||||
|
progressListener = progressListener
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
Timber.v("## Clear file")
|
Timber.v("## Uploading clear file")
|
||||||
encryptedFile = null
|
encryptedFile = null
|
||||||
fileUploader
|
fileUploader.uploadFile(
|
||||||
.uploadFile(fileToUpload, attachment.name, attachment.getSafeMimeType(), progressListener)
|
file = fileToUpload,
|
||||||
|
filename = attachment.name,
|
||||||
|
mimeType = attachment.getSafeMimeType(),
|
||||||
|
progressListener = progressListener
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Timber.v("## Update cache storage for ${contentUploadResponse.contentUri}")
|
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 encryptionResult = MXEncryptedAttachments.encryptAttachment(thumbnailData.bytes.inputStream(), thumbnailData.mimeType)
|
||||||
val contentUploadResponse = fileUploader.uploadByteArray(
|
val contentUploadResponse = fileUploader.uploadByteArray(
|
||||||
byteArray = encryptionResult.encryptedByteArray,
|
byteArray = encryptionResult.encryptedByteArray,
|
||||||
filename = "thumb_${params.attachment.name}",
|
filename = null,
|
||||||
mimeType = MimeTypes.OctetStream,
|
mimeType = MimeTypes.OctetStream,
|
||||||
progressListener = thumbnailProgressListener
|
progressListener = thumbnailProgressListener
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user