I've configured the REST channel for file upload according to IBM article http://www-01.ibm.com/support/knowledgecenter/SS7K4U_7.0.0/com.ibm.websphere.web2mobile.mobile.application.services.help/docs/fileuploader_README.html?cp=SS7K4U_7.0.0%2F8-13-3 :
import org.apache.wink.common.model.multipart.BufferedInMultiPart;
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@Path("/upload")
public RestResult upload(BufferedInMultiPart bimp) {
List<InPart> parts = bimp.getParts();
// ....
}
I've added the test consumption of the stream, just to make sure the request is fully processed:
IOUtils.copy(part.getInputStream(), new NullOutputStream());
I've tested the whole with really big uploades - about 100MB. I've noticed the dramatic memory usage increase on Websphere server, much bigger that by uploading little files. I assume this is caused by the uploaded file being placed into memory after upload, and before calling my upload
function.
Is it possible to configure the tool so that the big files are read into some temporary file, instead of memory?
Or is it possible to become the incoming input stream directly in the REST channnel method?
I'm using Websphere 8.5 and JAX-WS REST channel.
According to Apache Wink documentation found here, it seems that BufferedInMultiPart stores complete file into memory, so try to replace BufferedInMultiPart with InMultiPart:
import org.apache.wink.common.model.multipart.InMultiPart;
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@Path("/upload")
public RestResult upload(InMultiPart bimp) {
List<InPart> parts = new ArrayList<InPart>();
while(bimp.hasNext()) {
parts.add(bimp.next());
}
// ....
}