Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 48
Registered: ‎08-07-2013
My Device: z10
My Carrier: blackberry

Zip file uploading using Qmultipart/form-data post

hi,

  

       can any one help me to upload a zipfile using Qmultipart in bb cascades.

 

thank you,

Developer
Posts: 145
Registered: ‎12-23-2012
My Device: BB10 Dev Alpha
My Carrier: wifi

Re: Zip file uploading using Qmultipart/form-data post

Try following sample.
 
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
 
 QHttpPartzipPart;
zipPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/zip"));
zipPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"zipfile\"; filename=\"zipfile.zip\""));
QFile *file = new QFile("zipfile.zip");
file->open(QIODevice::ReadOnly);
zipPart.setBodyDevice(file);
file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
 
multiPart->append(zipPart);
 
QUrl url("URL");
QNetworkRequest request(url);
 
QNetworkAccessManager manager;
QNetworkReply *reply = manager.post(request, multiPart);
multiPart->setParent(reply);