11#include <QTemporaryFile>
24 return d->headers.contentType();
38 QString fileTemplate = QStringLiteral(
"%1/qt_temp.XXXXXX");
49 qint64 posOrig = d->pos;
54 qint64 in =
read(block,
sizeof(block));
58 if (in != out.
write(block, in)) {
70 if (!error && !out.
rename(newName)) {
72 setErrorString(QStringLiteral(
"Cannot create %1 for output").arg(newName));
86 std::unique_ptr<QTemporaryFile> ret;
88#ifndef QT_NO_TEMPORARYFILE
91 ret = std::make_unique<QTemporaryFile>();
93 ret = std::make_unique<QTemporaryFile>(templateName);
98 qint64 posOrig = d->pos;
103 qint64 in =
read(block,
sizeof(block));
108 if (in != ret->write(block, in)) {
124 qCWarning(CUTELYST_UPLOAD) <<
"Failed to open temporary file.";
128 Q_UNUSED(templateName);
143 return d->endOffset - d->startOffset;
161 open(prv->device->openMode());
162 const QByteArray disposition = prv->headers.contentDisposition();
163 int start = disposition.
indexOf(
"name=\"");
166 int end = disposition.
indexOf(u
'"', start);
173 start = disposition.
indexOf(
"filename=\"");
176 int end = disposition.
indexOf(
'"', start);
197 qint64 posOrig = d->device->pos();
199 d->device->seek(d->startOffset + d->pos);
200 qint64 len = d->device->read(data, qMin(
size() - d->pos, maxlen));
201 d->device->seek(posOrig);
209 qint64 posOrig = d->device->pos();
211 d->device->seek(d->startOffset + d->pos);
212 qint64 len = d->device->readLine(data, qMin(
size() - d->pos, maxlen));
213 d->device->seek(posOrig);
225#include "moc_upload.cpp"
Cutelyst Upload handles file upload requests.
Upload(UploadPrivate *prv)
bool seek(qint64 pos) override
qint64 pos() const override
qint64 readLineData(char *data, qint64 maxlen) override
qint64 writeData(const char *data, qint64 maxSize) override
QByteArray contentType() const
virtual ~Upload() override
qint64 readData(char *data, qint64 maxlen) override
qint64 size() const override
std::unique_ptr< QTemporaryFile > createTemporaryFile(const QString &templateName={})
bool save(const QString &filename)
The Cutelyst namespace holds all public Cutelyst API.
qsizetype indexOf(QByteArrayView bv, qsizetype from) const const
QByteArray sliced(qsizetype pos) const const
bool open(FILE *fh, QIODeviceBase::OpenMode mode, QFileDevice::FileHandleFlags handleFlags)
bool rename(const QString &newName)
virtual void close() override
virtual bool atEnd() const const
QString errorString() const const
virtual bool open(QIODeviceBase::OpenMode mode)
QByteArray read(qint64 maxSize)
virtual bool seek(qint64 pos)
void setErrorString(const QString &str)
qint64 write(const QByteArray &data)
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const