I completely blanked out, here's the code of the servlet that handles
the upload from SwfUploader and tries to dispatch to the Blobstore:
String postUploadUrl = null;
try {
BlobstoreService blobstoreService =
BlobstoreServiceFactory.getBlobstoreService();
postUploadUrl = blobstoreService.createUploadUrl("/
postUpload");
// in production, the blobstore service produces an absolute
URL which the request dispatcher doesn't like, so we need to strip it
down to a path...
int ahUploadIndex = postUploadUrl.indexOf("/_ah/upload");
// we want to chop off the prefix cause we want to forward to
it
postUploadUrl = postUploadUrl.substring(ahUploadIndex);
logger.info("About to forward to blobstore service to: " +
postUploadUrl);
// --------------- ***** This is where I get 404's when I
deploy to production, but works fine in the local dev server
*********----------------//
request.getRequestDispatcher(postUploadUrl).forward(request,
response);
} catch (Throwable t) {
logger.log(Level.SEVERE,"Failed in forwarding request to "
+ postUploadUrl,t);
}
Any tips would be highly appreciated.
Regards,
Alex Kotchnev
On Jan 20, 1:24 am, akochnev <[email protected]> wrote:
> I'm trying to set up a file upload in my application based on
> SwfUploader (http://swfupload.org), and I'm coming to my wits end
> about how to proceed. I use Tapestry5 for my application (http://
> tapestry.apache.org/tapestry5.1) but I think for the most part that's
> beside the point.
>
> First, I create a servlet mapped to a path (/postUpload) that is used
> in generating the Blobstore upload URL using the BlobStoreService.
> When I generate an upload URL and point a single file upload to that
> URL using the SwfUploader, the first file is uploaded successfully.
> However, one of the big benefits of SwfUploader is the ability to
> queue up multiple files to be uploaded. The problem is that after the
> first file is uploaded to the given URL, the subsequent file uploads
> to the same URL fail (as evidently, the Blobstore prefers to have a
> separate URL for each upload). OK, I accept that as a choice of the
> API.
>
> Now, because the blobstore API and SwfUploader are third party
> components, I have to have something in the middle that mediates the
> differences. The solution I came up with is as follows:
> 1. Create a servlet (e.g. mapped to /upload) to which the SwfUploader
> submits all requests.
> 2. Configure SwfUPloader to post to that URL
> 3. Configure the servlet to generate a new BlobstoreSErvice URL for
> each request and then use the request.getRequestDispatcher("...
> blobstore generated url...").forward(request,response).
>
> In this way, all the third party pieces should be happy : SwfUPloader
> gets to upload to the same URL every time, and the Blobstore is
> receives an upload to a new URL every time. Now, in the dev server,
> this approach works beautifully, my files get uploaded and I can see
> them in the dev server blobstore.
>
> Now, the problem : when I upload my app to GAE, the file upload stops
> working, I start getting 404 errors and the files do not get uploaded.
> I think that I eliminated the first problem : in production GAE
> blobstoreService generates absolute URLs : e.g. while the dev server
> generated /_ah/upload?d.....dsf... URLs, in prod they
> arehttp://foo.com/_ah/upload... and AFAIK, the request dispatcher
> requires a path (e.g. /foo/bar) with the app, not an absolute URL
> (e.g.http://foo.com/_ah/upload...).
>
> I tried tackling the issue by just stripping out the server name from
> the Blobstore generated URL, but to no avail. I continue getting the
> same 404 errors. Just for a good measure, if I comment out the passing
> of the original request and response to the request dispatcher, the
> servlet responds just fine (that is, I wanted to make sure that the
> servlet is properly mapped, etc).
>
> So, I'm stumped. The only possible next step to get this working would
> be to hack up SwfUploader so that I can specify a different URL for
> each submission. I thought about using the URL fetch service to send a
> POST to the blobstore URLs, but I'm not sure how I can add the
> uploaded file data.
>
> I like the Blobstore API in that it gives a decent solution to the
> fileupload problem and I'd like to use the Blobstore. If that doesn't
> work, I guess I'd have to go back to uploading into a blob in the
> database using my own code (and dealing w/ the subsequent restrictions
> - e.g. 1 MB entity, etc).
>
> Any tips ? Ideas of where I should proceed to ?
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" 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-java?hl=en.