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
Developer
ekke
Posts: 1,458
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone
Accepted Solution

QHttpMultiPart Bug Qt 4.8.0, 4.8.1 - HowTo workaround ? (UploadFile fails)

[ Edited ]

found a bug in QHttpMultiPart causing problems to upload files

 

here's the bug: https://bugreports.qt-project.org/browse/QTBUG-25429

 

the bug is fixed: https://codereview.qt-project.org/#change,24142

 

but not in the Qt Version bundled with Cascades

 

QHttpMultiPart is missing a CRLF at the end after the last boundary.

Any idea to workaround ?

 

appended some Parts to the Multipart and then do a Post

 

mNetworkAccessManager->post(request, mRequestMultipart);

 have no idea HowTo add a CRLF to the Multipart and want to avoid to construct the complex MultiPart manually

 

ekke

see also this thread: http://supportforums.blackberry.com/t5/Cascades-Development/JAX-RS-vs-Qt-Multipart-Formdata/td-p/200...

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Developer
ekke
Posts: 1,458
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: QHttpMultiPart Bug Qt 4.8.0, 4.8.1 - HowTo workaround ? (UploadFile fails)

Qt 4.8.3 fixed the bug 25429 http://qt.digia.com/Release-Notes/Release-Notes-Qt-Commercial-483/

hopefully Cascades will be bundled with Qt 4.8.3 soon

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Developer
rnickel
Posts: 62
Registered: ‎10-29-2008
My Device: 9800
My Carrier: Rogers

Re: QHttpMultiPart Bug Qt 4.8.0, 4.8.1 - HowTo workaround ? (UploadFile fails)

I finally had success in uploading an image along with some other parameters.

 

QString fn = QDir::currentPath() + "/app/native/assets/images/icon.png";

QNetworkAccessManager* netManager = new QNetworkAccessManager();
if (!netManager)
{
    qDebug() << "Unable to create QNetworkAccessManager!";
    emit complete("Unable to create QNetworkAccessManager!", false);
    return;
}

QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);

QHttpPart commentPart;
commentPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"comment\""));
commentPart.setBody("Comment goes here");

QHttpPart namePart;
namePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"name\""));
namePart.setBody("Name goes here");

QHttpPart imagePart;
imagePart.setHeader(QNetworkRequest::ContentTypeHeader, "image/png");
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"image\"; filename=\"icon.png\""));

QFile *file = new QFile(fn);
file->open(QIODevice::ReadOnly);
imagePart.setBodyDevice(file);
file->setParent(multiPart);


multiPart->append(commentPart);
multiPart->append(namePart);
multiPart->append(blankImagePart);
multiPart->append(sectionPart);
multiPart->append(latPart);
multiPart->append(lonPart);
multiPart->append(imagePart);

QString queryUri = "http://your.urlhere.com";
QUrl url(queryUri);

QNetworkRequest req(url);

QNetworkReply* ipReply = netManager->post(req, multiPart);
connect(ipReply, SIGNAL(finished()), this, SLOT(commentDataReceived()));

 

Please use plain text.
Developer
ekke
Posts: 1,458
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: QHttpMultiPart Bug Qt 4.8.0, 4.8.1 - HowTo workaround ? (UploadFile fails)

thx

 

I will do more tests tomorrow evening with a manual implementation and also with Beta 4 where Qt 4.8.4 is integrated where the bug should be fixed as I got infos from RIM

 

...will let you know (and also take a look at your code)

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Developer
ekke
Posts: 1,458
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: QHttpMultiPart Bug Qt 4.8.0, 4.8.1 - HowTo workaround ? (UploadFile fails)

thx rnickel - comparing with your code I found the reason:

 

there was one line too much in my code:

 

request.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data");

 I had to comment this out and now it works. (The bug with QHttpMultiPart and missing CRLF at the end is fixed with Qt 4.8.4 bundled with Cascades)

Seems that QHttpMultiPart was too intelligent and comfortable for me ;-)

...but should be mentioned in the docs that the multipart-header must not be set or should be ignored

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Forums Advisor I
vaishali28
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: QHttpMultiPart Bug Qt 4.8.0, 4.8.1 - HowTo workaround ? (UploadFile fails)

Hey 

I have applied the above code in my app but its showing an File uploading error.

Can you help me in resolving it??

 

Thanks in advance

Please use plain text.