I'm trying to user the BlobstoreService in order to upload images to my application. According to the GAE API this is how you should do it:
<form action="<%= blobstoreService.createUploadUrl("/upload") %>" method="post" enctype="multipart/form-data">
<input type="file" name="myFile">
<input type="submit" value="Submit">
</form>
My problem is that I cannot use JSP because I'm using phonegap to create an android app and JSPs are not supported so I do this in another way, I have one servlet that receive the request, genarated the URL and forward the request to the generated URL like this:
GetBlobstoreServiceUrlServlet:
String url = blobstoreService.createUploadUrl("/AddDogPictureServlet");
int ahUploadIndex = url.indexOf("/_ah/upload");
url = url.substring(ahUploadIndex);
ServletContext context = getServletContext();
RequestDispatcher rd = context.getRequestDispatcher(url);
rd.forward(request, response);
This is working perfectly when I run it on my local computer but when I upload it to the GAE I'm getting "Error: NOT_FOUND" on this servlet only.
I have other serlets and all of them are working fine.
I checked the web.xml file and the servlet mapped correctly (otherwise it would not worked locally):
<servlet>
<servlet-name>GetBlobstoreServiceUrlServlet</servlet-name>
<servlet-class>Servlets.BlobstoreServlets.GetBlobstoreServiceUrlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GetBlobstoreServiceUrlServlet</servlet-name>
<url-pattern>/GetBlobstoreServiceUrlServlet</url-pattern>
</servlet-mapping>
Is there another way to achieve this goal?
The problem is that, in production, the generated blob upload Urls (createUploadUrl(..)
) are on servers separate from your app servers. OTOH requestDispatcher.forward(..)
only works within the same servlet container. This works on development server because blob upload urls are simulated and run in the same servlet container.
The solution is either to: