简体   繁体   中英

Storing uploaded images on Google App Engine with Java

I am looking at writing a Java web application on Google App Engine. I want to be able to upload and serve images from the app but just realised that the Datastore have a 1MB limit. This is slightly too little for decent pictures. Is there an alternative way you can suggest of doing this? Perhaps storing those as static content rather than in the Datastore but there seems to be no API for this.

Now it is possible on GAE. Simply you have to store your files in Blobstore . You can upload your files like this:

<body>
<form action="<%= blobstoreService.createUploadUrl("/upload") %>" method="post" enctype="multipart/form-data">
    <input type="file" name="myFile">
    <input type="submit" value="Submit">
</form>

And then to serve file from servlet:

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
    BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
    blobstoreService.serve(blobKey, res);

You can't write to the filesystem in App Engine, so static content is out for now - but an API for storing and serving blobs is on the roadmap. In the meantime, your best bet is to split the file into chunks, and store those in the datastore, or to use an external service like S3.

There is no easy way today, but that can change later.

The best you can do right now is to vote (star) the request to add Google File System support to appengine in their issue tracker:

Now Google App enigne provides Image API which is different from Blobstore API. this is improved and specially for Images. you can try that.

https://cloud.google.com/appengine/docs/java/images/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM