From a90f50f9f08f797b00f74d78a5fc2d7042acff75 Mon Sep 17 00:00:00 2001 From: Jan Blackquill Date: Thu, 3 Feb 2022 00:54:03 -0500 Subject: [PATCH] refactor: use mimeTypeForFileNameAndData --- app/stores/uploading.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/stores/uploading.h b/app/stores/uploading.h index 3e18ecc..5143909 100644 --- a/app/stores/uploading.h +++ b/app/stores/uploading.h @@ -21,21 +21,22 @@ inline Croutons::FutureResult uploadFile(State* state, QString host, QU file->open(QIODevice::ReadOnly); const auto fname = QString::fromLocal8Bit(QUrl::toPercentEncoding(url.fileName())); + const auto mimetype = QMimeDatabase().mimeTypeForFileNameAndData(url.fileName(), file); + file->seek(0); QHttpPart filePart; filePart.setBodyDevice(file); filePart.setHeader( QNetworkRequest::ContentDispositionHeader, QString("form-data; name=\"file\"; filename=\"%1\"").arg(fname)); - QMimeDatabase db; - const auto mt = db.mimeTypeForUrl(url); - filePart.setHeader(QNetworkRequest::ContentTypeHeader, mt.name()); + + filePart.setHeader(QNetworkRequest::ContentTypeHeader, mimetype.name()); mp->append(filePart); QUrlQuery query; query.addQueryItem("filename", url.fileName()); - query.addQueryItem("contentType", QMimeDatabase().mimeTypeForFile(furl).name()); + query.addQueryItem("contentType", mimetype.name()); auto c = co_await state->api()->clientForHomeserver(host);