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));
57 if (in != out.
write(block, in)) {
69 if (!error && !out.
rename(newName)) {
71 setErrorString(QStringLiteral(
"Cannot create %1 for output").arg(newName));
85 std::unique_ptr<QTemporaryFile> ret;
87#ifndef QT_NO_TEMPORARYFILE
90 ret = std::make_unique<QTemporaryFile>();
92 ret = std::make_unique<QTemporaryFile>(templateName);
97 qint64 posOrig = d->pos;
102 qint64 in =
read(block,
sizeof(block));
106 if (in != ret->write(block, in)) {
122 qCWarning(CUTELYST_UPLOAD) <<
"Failed to open temporary file.";
126 Q_UNUSED(templateName);
141 return d->endOffset - d->startOffset;
159 open(prv->device->openMode());
160 const QByteArray disposition = prv->headers.contentDisposition();
161 int start = disposition.
indexOf(
"name=\"");
164 int end = disposition.
indexOf(u
'"', start);
171 start = disposition.
indexOf(
"filename=\"");
174 int end = disposition.
indexOf(
'"', start);
195 qint64 posOrig = d->device->pos();
197 d->device->seek(d->startOffset + d->pos);
198 qint64 len = d->device->read(data, qMin(
size() - d->pos, maxlen));
199 d->device->seek(posOrig);
207 qint64 posOrig = d->device->pos();
209 d->device->seek(d->startOffset + d->pos);
210 qint64 len = d->device->readLine(data, qMin(
size() - d->pos, maxlen));
211 d->device->seek(posOrig);
223#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