I am using qt(5.3) on windows 7(vs2008)(below code, skipping the details) to upload a file which is on the disk. if the proxy is not enabled on the system,
upload is working fine for any size(i tried ~3gb) without spiking memory for my application(~22MB). But as i enable system proxy, memory for the application
is growing propotional to uploadProgress. It works fine with file size below 1.3GB upload. As my application is 32 bit, it crashes(bad_alloc, in qt) if i try to
upload more than 1.3GB file with proxy.
So i have following queries:
1) Are we loading complete file into memory if proxy is enabled?
2) As i guess, we are not loading complete file into memory if proxy is not enabled. Can we do same thing if proxy is enabled? If yes, how can we achieve that?
QNetworkReply
* upload
(const QString &title,
const QString &path,
const QString &payload, QNetworkRequest request, QNetworkAccessManager
* nam
)
QHttpMultiPart *pMultipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart richPart;
richPart.
setHeader(QNetworkRequest
::ContentDispositionHeader,
QVariant("form-data; name=\"entity_document\""));
richPart.
setHeader(QNetworkRequest
::ContentTypeHeader,
QVariant("application/json; charset=UTF-8"));
richPart.setBody(payload.toUtf8());
QString binaryHeader
= "form-data; name=\"fileData\"; filename=\"";
binaryHeader += title;
binaryHeader += "\"";
QHttpPart binaryHeader;
binaryHeader.
setHeader(QNetworkRequest
::ContentTypeHeader,
QVariant("text/plain; charset=UTF-8"));
binaryHeader.
setHeader(QNetworkRequest
::ContentDispositionHeader,
QVariant(binaryHeader
));
{
//logging the error
}
binaryHeader.setBodyDevice(fileP);
fileP->setParent(pMultipart);
pMultipart->append(richPart);
pMultipart->append(binaryHeader);
m_replyP = nam->post(request, pMultipart);
pMultipart->setParent(m_replyP);
//bindall(); here binding finished() and uploadProgress signal
return m_replyP;
}
//Skipped normal memory cleanup
QNetworkReply* upload(const QString &title, const QString &path, const QString &payload, QNetworkRequest request, QNetworkAccessManager* nam)
QHttpMultiPart *pMultipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart richPart;
richPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"entity_document\""));
richPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json; charset=UTF-8"));
richPart.setBody(payload.toUtf8());
QString binaryHeader = "form-data; name=\"fileData\"; filename=\"";
binaryHeader += title;
binaryHeader += "\"";
QHttpPart binaryHeader;
binaryHeader.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain; charset=UTF-8"));
binaryHeader.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(binaryHeader));
QFile *fileP = new QFile(path);
if(!fileP->open(QIODevice::ReadOnly))
{
//logging the error
}
binaryHeader.setBodyDevice(fileP);
fileP->setParent(pMultipart);
pMultipart->append(richPart);
pMultipart->append(binaryHeader);
m_replyP = nam->post(request, pMultipart);
pMultipart->setParent(m_replyP);
//bindall(); here binding finished() and uploadProgress signal
return m_replyP;
}
//Skipped normal memory cleanup
To copy to clipboard, switch view to plain text mode
Applicatin initialization if Proxy is enabled on machine:
applicationProxy.setUser(user);
applicationProxy.setPassword(password);
nam->setProxy(applicationProxy);
QNetworkProxy applicationProxy = QNetworkProxy::applicationProxy();
applicationProxy.setUser(user);
applicationProxy.setPassword(password);
QNetworkProxy::setApplicationProxy(applicationProxy);
nam->setProxy(applicationProxy);
To copy to clipboard, switch view to plain text mode
Bookmarks