Here is what I did:
1. Rendered a normal form without a specific form action
2. Requested a upload URL from the BlobstoreService via jQuery and set
the action attribute on the form
3. User posts the form to the form action.
Here are my controllers:
@RequestMapping(value = "/post/path", method = RequestMethod.GET)
@ResponseBody
public String postPath() {
return gson.toJson(new Text(blobstoreService
.createUploadUrl("/post")));
}
@RequestMapping(value = "/post", method = RequestMethod.POST)
@ResponseBody
public void post(HttpServletRequest request, HttpServletResponse response)
throws IOException {
Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(request);
BlobKey blobKey = blobs.get("imageFile");//file upload input
logger.info("blob key="+blobKey);
BlobInfoFactory bif = new BlobInfoFactory();
BlobInfo bi = bif.loadBlobInfo(blobKey);
logger.info("blob size="+bi.getSize());
ImagesService imagesService = ImagesServiceFactory.getImagesService();
Image original = ImagesServiceFactory.makeImageFromBlob(blobKey);
logger.info("original image=" + original);
}
The jQuery to set the form action is:
$.getJSON('/api/listings/post/path', function(data) {
$('#post_form').attr('action', data.value);
});
You could easily skip the ajax part by putting the form action as a model
attribute when the page is rendered.
-Tristan
On Tue, Dec 28, 2010 at 2:17 AM, Sgurbat <[email protected]> wrote:
> Hi all, for first sorry for my english.
>
> I'm using GAE with the Java Spring3 Framework. Everything works fine
> but now I need to upload and save a simple image for each "Book" model
> in my application.
>
> I have some annotated controller with Spring3 that respond to some
> URLs but I don't know how to handle the uploaded file.
>
> I mean, I have a simple Controller like this:
>
> @Controller
> @RequestMapping(value = "/admin/book/add.htm")
> public class BookAddController {
> ...
> }
>
> I don't know how to do with the JSP.
> <form:form modelAttribute="book" action="<%=
> blobstoreService.createUploadUrl("/upload") %>" method="post"
> enctype="multipart/form-data">
>
> because if I set the action attribute to that path I'm unable to
> persist the "Book" model, because the BookAddController, obviously,
> doesn't work.
>
> The documentation and the examples I've found are all about a classic
> standard servlet so I'm a little bit confused.
>
> Can you help me?
>
> Thanks a lot.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.