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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Highlighted
Developer
Posts: 1,749
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
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
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 1,749
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
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
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
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()));

 

Developer
Posts: 1,749
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
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
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 1,749
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
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
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Forums Advisor I
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