I have created a servlet that accepts an image from my android app.I am receiving bytes on my servlet, however, I want to be able to save this image with the original name on the server. How do I do that. I dont want to use apache commons. Is there any other solution that would work for me?
thanks
Send it as a multipart/form-data request with help of
MultipartEntity
class of Android's builtin HttpClient API.And then in servlet's
doPost()
method, use Apache Commons FileUpload to extract the part.Unless you're using Servlet 3.0 which supports
multipart/form-data
request out the box withHttpServletRequest#getParts()
, you would need to reinvent a multipart/form-data parser yourself based on RFC2388. It's only going to bite you on long term. Hard. I really don't see any reasons why you wouldn't use it. Is it plain ignorance? It's at least not that hard. Just dropcommons-fileupload.jar
andcommons-io.jar
in/WEB-INF/lib
folder and use the above example. That's it. You can find here another example.