Announcement Announcement Module
Collapse
No announcement yet.
Spring showcase with image from camera. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring showcase with image from camera.

    Hi There,
    I am trying to modify the example "HttpPostFormDataActivity" to use an image taken from the camera rather than an image loaded from the <code>Resource resource = new ClassPathResource("res/drawable/spring09_logo.png");</code>

    I have got it all hanging together except one critcal part:

    For
    Code:
    formData.add("file", resource);
    I had tried :
    Code:
    			ByteArrayOutputStream bos = new ByteArrayOutputStream();
    			photo.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
    			byte[] bitmapdata = bos.toByteArray();
    			resource = new ByteArrayResource(bitmapdata);
    			formData.add("file", resource);
    What must resource now be in order for it to be accepted by the Server:


    Code:
     @RequestMapping(value = "postformdata", method=RequestMethod.POST, headers="Content-Type=multipart/form-data")
        public @ResponseBody String handleFormUpload(@RequestParam("description") String description, @RequestParam("file") MultipartFile file) {

    I was going to go down the route or creating a temp file with the image just taken and use the same code? Is the a correct approach.

    Any help / guidance would be appreciated.

  • #2
    This approach should work. Once you have the file on the server, you can getBytes() from it and persist it to a file or a database, whichever you like.

    One addition in Spring Framework 3.1 is the "consumes" parameter. You can update your @RequestMapping as follows:

    @RequestMapping(value = "postformdata", method = RequestMethod.POST, consumes = "multipart/form-data")

    Here is a nice tutorial on how to retrieve the image from the camera, just as additional information for others.
    http://mobile.tutsplus.com/tutorials...ng-the-camera/

    Comment

    Working...
    X