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

Java Development

Reply
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Using MultipartPostData for binary data?

How would I use MultipartPostData to build a request with fields containing binary data (as if uploading file from an html form) as well as text data? There was a previous thread that basically asked the same question, but there was no good answer--somehow setData(Object) is supposed to be used, but there's no documentation or examples of how to use it. A Google search didn't turn up anything useful, either. Would something like this work?

 

byte[] face; byte[] voice; // set face to some image data // set voice to some sound data MultipartPostData post = new MultipartPostData("UTF-8", true); post.append("name", "GI Joe"); post.append("face", null); post.setData(face); post.append("voice", null); post.setData(voice); // etc.

 

Moreover, how can we control the content-type of each part? How, for instance, could I build a request that had, say, image/png, audio/basic, application/octet-stream, and text/xml fields?

If MultipartPostData can't do this, is there something better in the RIM APIs?

Also, what is the intended use of the constants PostData.ENCTYPE_MULTIPART_FORMDATA and PostData.ENCTYPE_URLENCODED? These are int values and I can't find any part of the API that might use them.

 




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Using MultipartPostData for binary data?

*bump*



Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 176
Registered: ‎11-06-2008
My Device: Not Specified

Re: Using MultipartPostData for binary data?

[ Edited ]

I haven't used this myself but I know of someone who did use the following code for inspiration and got it working in his own app

 

http://wiki.forum.nokia.com/index.php/HTTP_Post_multipart_file_upload_with_J2ME


Message Edited by jhw1701 on 09-18-2009 12:58 PM
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Using MultipartPostData for binary data?

That's a useful link. It shows how to implement a replacement for RIM's MultipartPostData class. It isn't an answer to the question I asked, but it is a solution to my problem! :smileyhappy:

 

Thanks!




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.