aboutsummaryrefslogtreecommitdiff
path: root/lib/connection.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-01-06 00:12:05 +0900
committerGitHub <noreply@github.com>2019-01-06 00:12:05 +0900
commit9c08bbce341081a8ccbe0fccf48658b3e75e02cf (patch)
tree171ff3fcf35acb2c4a707488e6f43a2e35fff56f /lib/connection.cpp
parentf545d181ade8736dfda93e8abb34ab93ac34e931 (diff)
parent27555e44dfbaae26a0e030cb3c22eb00ba8371f0 (diff)
downloadlibquotient-9c08bbce341081a8ccbe0fccf48658b3e75e02cf.tar.gz
libquotient-9c08bbce341081a8ccbe0fccf48658b3e75e02cf.zip
Merge pull request #272 from QMatrixClient/kitsune-upload-attachments
Support of attachments uploading
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r--lib/connection.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index a16bc753..c17cbffc 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -43,6 +43,7 @@
#include <QtCore/QStringBuilder>
#include <QtCore/QElapsedTimer>
#include <QtCore/QRegularExpression>
+#include <QtCore/QMimeDatabase>
#include <QtCore/QCoreApplication>
using namespace QMatrixClient;
@@ -466,13 +467,21 @@ MediaThumbnailJob* Connection::getThumbnail(const QUrl& url,
}
UploadContentJob* Connection::uploadContent(QIODevice* contentSource,
- const QString& filename, const QString& contentType) const
+ const QString& filename, const QString& overrideContentType) const
{
+ auto contentType = overrideContentType;
+ if (contentType.isEmpty())
+ {
+ contentType =
+ QMimeDatabase().mimeTypeForFileNameAndData(filename, contentSource)
+ .name();
+ contentSource->open(QIODevice::ReadOnly);
+ }
return callApi<UploadContentJob>(contentSource, filename, contentType);
}
UploadContentJob* Connection::uploadFile(const QString& fileName,
- const QString& contentType)
+ const QString& overrideContentType)
{
auto sourceFile = new QFile(fileName);
if (!sourceFile->open(QIODevice::ReadOnly))
@@ -482,7 +491,7 @@ UploadContentJob* Connection::uploadFile(const QString& fileName,
return nullptr;
}
return uploadContent(sourceFile, QFileInfo(*sourceFile).fileName(),
- contentType);
+ overrideContentType);
}
GetContentJob* Connection::getContent(const QString& mediaId) const