Multipart upload to appengine

好久不见. 提交于 2019-12-19 05:00:09

问题


I'm having multiple problems with appengine (java/jersey), but now I'm stucked with uploading files via multipart.

I've read this answer: https://stackoverflow.com/a/31325201

It worked for localhost, but when I upload to appengine, it shows the same error when starting the server:

java.lang.SecurityException: Unable to create temporary file

Does anyone know why it can be?

Thanks!


回答1:


You have to use Blobstore for uploading.

Call blobstoreService.createUploadUrl to create an upload URL for the form that the user will fill out, passing the application path to load when the POST of the form is completed.

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

and then in servlet:

Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
List<BlobKey> blobKeys = blobs.get("myFile");

You can upload files to Storage directly, but passing UploadOptions to .createUploadUrl:

UploadOptions options = new UploadOptions.Builder().withGoogleStorageBucketName("mybucket");
String uploadUrl = blobstoreService.createUploadUrl("/upload", options)

Follow documentation https://cloud.google.com/appengine/docs/java/blobstore/#Java_Uploading_a_blob



来源:https://stackoverflow.com/questions/37731114/multipart-upload-to-appengine

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