将分段上传到appengine [英] Multipart upload to appengine

查看:95
本文介绍了将分段上传到appengine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我读过这个答案。 : https://stackoverflow.com/a/31325201



它为localhost工作,但是当我上传到appengine时,它在启动服务器时显示相同的错误:

  java.lang.SecurityException :无法创建临时文件

有谁知道它为什么可以?



谢谢!

解决方案



调用 blobstoreService.createUploadUrl 为用户填写的表单创建一个上传URL,传递应用程序路径以加载POST表格已完成。

 < body> 
< form action =<%= blobstoreService.createUploadUrl(/ upload)%> method =postenctype =multipart / form-data>
< input type =filename =myFile>
< input type =submitvalue =提交>
< / form>
< / body>

然后在servlet中:

 映射< String,List< BlobKey>> blobs = blobstoreService.getUploads(req); 
列表< BlobKey> blobKeys = blobs.get(myFile);

您可以直接将文件上传到存储,但传递 UploadOptions .createUploadUrl

  UploadOptions options = new UploadOptions。 。生成器()withGoogleStorageBucketName( mybucket); 
String uploadUrl = blobstoreService.createUploadUrl(/ upload,options)

a href =https://cloud.google.com/appengine/docs/java/blobstore/#Java_Uploading_a_blob =nofollow> https://cloud.google.com/appengine/docs/java/blobstore/# Java_Uploading_a_blob


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!

解决方案

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

这篇关于将分段上传到appengine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆