Storing uploaded images on Google App Engine with Java

試著忘記壹切 提交于 2019-12-12 10:59:32

问题


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.


回答1:


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);



回答2:


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.




回答3:


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:

  • Add GFS API support to GAE - http://code.google.com/p/googleappengine/issues/detail?id=1199



回答4:


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/



来源:https://stackoverflow.com/questions/1100573/storing-uploaded-images-on-google-app-engine-with-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!