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

JAX-RS vs Qt (Multipart Formdata)

[ Edited ]

perhaps someone has an idea what I'm doing wrong.

I have to implement server connections for Cascades and so far all works well,

requests are working for JSON and Stream Downloads

 

the only problem yet is Uploading a file to the server

 

here's some existing Java Code for Jax-RS using com.sun.jersey

FormDataMultiPart f = new FormDataMultiPart();
f.field("token", this.token);
f.field("file_length", "" + length);
f.field("group_pk", "" + groupPk);
f.field("log_uc", this.username);
f.field("comment", comment);
f.field("expiration_date", "");
f.field("parent_path", parentPath);
f.field("overwrite", (overwrite ? "1" : "0"));
f.bodyPart(new StreamDataBodyPart("file_attachment", is, name));

 and here's my Cascades/Qt-Code

mRequestMultipart = new QHttpMultiPart(QHttpMultiPart::FormDataType, this);
fileLengthPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form.data; name=\"file_length\""));
fileLengthPart.setBody(QString::number(mFileLength).toUtf8());
mRequestMultipart->append(fileLengthPart);
groupPkPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form.data; name=\"group_pk\""));
groupPkPart.setBody(QString::number(mGroupPk).toUtf8());
mRequestMultipart->append(groupPkPart);
parentPathPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form.data; name=\"parent_path\""));
parentPathPart.setBody(mParentPath.toUtf8());
mRequestMultipart->append(parentPathPart);
commentPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form.data; name=\"comment\""));
commentPart.setBody(mComment.toUtf8());
mRequestMultipart->append(commentPart);
logUcPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form.data; name=\"log_uc\""));
logUcPart.setBody(mUser.toUtf8());
mRequestMultipart->append(logUcPart);
expirationDatePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form.data; name=\"expiration_date\""));
expirationDatePart.setBody("");
mRequestMultipart->append(expirationDatePart);
tokenPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form.data; name=\"token\""));
tokenPart.setBody(mToken.toUtf8());
mRequestMultipart->append(tokenPart);
overWritePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form.data; name=\"overwrite\""));
overWritePart.setBody(QString::number(0).toUtf8());
mRequestMultipart->append(overWritePart);
fileAttachementPart.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream"); fileAttachementPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form.data; name=\"file_attachment\"; filename=\""+mFileName+"\"")); fileAttachementPart.setBodyDevice(mFileToUpload); mRequestMultipart->append(fileAttachementPart);

 this is the header

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

 server always replying "Bad Request"

 

think I'm overlooking something. perhaps the file attachment part is wrong ?

edited: added ContentTypeHeader and filename in fileAttachmentPart, but still no luck

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

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

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
simon_hain
Posts: 16,364
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: JAX-RS vs Qt (Multipart Formdata)

if you are using http you could put a proxy in between, like tcpmon, and check the differences between the headers from both approaches.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
ekke
Posts: 1,595
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: JAX-RS vs Qt (Multipart Formdata)

it's all https and I dont have the environment here to test this.

only developing the client against server running anywhere at customer site

 

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

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

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

Re: JAX-RS vs Qt (Multipart Formdata)

found the reason: a bug in Qt:

https://bugreports.qt-project.org/browse/QTBUG-25429

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

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

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900

Re: JAX-RS vs Qt (Multipart Formdata)

In all the examples ive seen, ive seen it form-data and not form.data. I doubt that makes a difference but maybe?

Like all of my posts
Developer
ekke
Posts: 1,595
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: JAX-RS vs Qt (Multipart Formdata)

thx mentioning this, Kyle

 

...don't remember where I found the example with form.data


kylefowler wrote:

In all the examples ive seen, ive seen it form-data and not form.data. I doubt that makes a difference but maybe?


changed all to form-data it's the same problem without the CRLF following the last boundary--

 

checked with the guy at customers server site - doesn't go thru to the server app - Apache Http server sends back with network error 'Bad request' because of the missing CRLF

 

the bug is fixed by Qt - but I have no idea if its possible to use this newer class in Cascades

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

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

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900

Re: JAX-RS vs Qt (Multipart Formdata)

Could always just wait and see if the next cascades update fixes things. Could be one of the things they knew about.

Like all of my posts
Developer
ekke
Posts: 1,595
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: JAX-RS vs Qt (Multipart Formdata)

[ Edited ]

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 Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner