Skip to main content

MultiPart Post with mobile Ajax

1 reply [Last post]
joersch
Offline
Joined: 2008-11-06
Points: 0

Hello,

i tried to send data as multi part content from mobile phone up to my server. I use the mobile ajax framework. (grateful framework!)
https://meapplicationdevelopers.dev.java.net/mobileajax.html

The server side works fine. (i checked with browser upload), But I dont know, how use i PostData and Part class. How do i use boundary etc?
Is there everybody they have a example, how can i do this?

regards

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
joersch
Offline
Joined: 2008-11-06
Points: 0

Hi,

i have a solution.
For interest:
static final String BOUNDARY = "---7d43722015402c8---";

Arg[] inputArgs = {
};

Arg[] itemHeaders = {
new Arg("Content-Type", "image/png"),
new Arg("Content-Disposition", "form-data; name=\"upload_field\"; filename=\"file.png\"")
};
Part item = new Part(picture, itemHeaders);
Part[] parts = {item};

PostData multiPart = new PostData(parts, BOUNDARY);

Arg[] httpArgs = {
new Arg("Content-Type", "multipart/form-data;boundary=" + BOUNDARY)
};

String url = midlet.getAppProperty("myUrl");
Response response = Request.post(url, inputArgs, httpArgs, listener, multiPart);

hope this helps