Designer 10.7 | webMethods Mobile Development | Code Snippets | Using Multipart Requests
 
Using Multipart Requests
The Request object for creating services in the Outline Editor supports multipart/form-data content types. A file upload is a typical use case for a multipart request.
The following snippet shows a sample implementation of an Agile Apps photo upload:
final Image img = getMyImage();
if (img != null) {
final UpdatePhotoRequest request = new UpdatePhotoRequest();
request.addOperationDelegate(this);

final StringBuffer xmlData = new StringBuffer();
xmlData.append("<platform><record>\r\n");
xmlData.append("<photo>photo.png</photo>\r\n");
xmlData.append("</record></platform>\r\n");

// add two parts to the multipart request
// first part is XML to tell Agile Apps about the data being uploaded
// second part is the image data to be uploaded
request.addBytePart(xmlData.toString().getBytes(), "_xml_data_",
"application/xml", false);
request.addImageFilePart(img, "photo.png", "photo", "image/png", false);

request.execute();
}
As of Mobile Development 9.8, AbstractMultipartRestOperation is available, which extends AbtractRestOperation for full support of multipart requests. Adding the following parts is currently supported by AbstractMultipartRestOperation:
*addBytePart(...)
*addFilePart(...)
*addImageFilePart(...)
As of Mobile Development 9.8, only image/png content type is supported when using addImageFilePart(...). This converts the given javax.microedition.lcdui.Image data automatically to PNG data.
For more information, see the Javadoc for AbstractMultipartRestOperation.
Related Topics