Thursday, June 7, 2012

Re: Generate URL to image stored on server

Because you need to use GWT.getHostPageBaseURL() not
GWT.getModuleBaseURL() (or use modulebase, but prepend "../" to your
filename). I assume the actual url to get the image is
http://127.0.0.1:8888/card_designer/exampleImage.jpg . That should get
the image.

BUT, going back to the "working directory" thing, it IS problematic to
write files there. At least, it is if you expect those files to be
there long term. Every time you redeploy a war in production, your app
server (tomcat, glassfish, whatever) will overwrite everything in the
directory which will erase working directories like card_designer. If
you just need some temporary space to store an image while the user
does things like cropping the image and then they download the
finished product, then that might be fine. But if they expect that url
to work long term, I wouldn't use that space.

(Also, don't know if you've considered the problem of lots of people
uploading images named the same thing or not.)

I recently had to do something similar to what you did. We have a
directory mounted on our production servers that holds uploaded images
(and isn't accessible via the web). When someone uploads a file, I
check the MD5 hash of the file to see if it's a match of another image
(in my use case, it's very probable that a user will upload the same
image or images every time they use the app). If it's not, then I
write the file to the shared directory in the MD5hash.ext format.
Either way, I then return the calculated filename to the GWT code.

The GWT code then immediately executes a request to a servlet hosted
at "/mymodule/images/*" and uses the path info to get the filename and
goes to look it up in the shared directory and relays the data through
the servlet.

Hope that's all clear enough.

Derek

On Jun 6, 12:09 pm, Gary <garyker...@googlemail.com> wrote:
> That makes sense. I have changed the location of storage to be the working
> directory:
>
> public static File dataDirectory = new File("card_designer");
>
> I prepend this File to each new File I open. So now I just need to
> construct a URL to grab these images.
>
> I have tried:
>
> public static String accessURL = GWT.getModuleBaseURL();
>
> On constructing an Image widget for my dynamic images, I append the
> relative filepath to this accessURL, as so:
>
> Image example = accessURL + "card_designer/exampleImage.jpg";
>
> However, I get a 404 file not found in my console on development mode:
>
> 404 - GET
> //http://127.0.0.1:8888/carddesigner/card_designer/exampleImage.jpg
> (127.0.0.1) 1444 bytes
>
> I think I'm close, but I don't understand why the GET request fails. The
> images is right there on the disk.
>
>
>
>
>
>
>
> On Wednesday, June 6, 2012 3:24:53 PM UTC+1, Piro wrote:
>
> > I don't think you can access files in this manner. If it would be possible
> > it would mean you can access any file on server(no security).
>
> > What you have to do is to store the file anywhere and generate some sort
> > of ID for it. Then you need to implement HTTP GET request by servlet.
> > Servlet will need to map ID to file location and write file to response
> > (and set some things like content type).
>
> > Iam sure there are other ways (REST,...).
> > Piro

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment