App Engine云存储RequestPayloadTooLargeException文件超出了10 MB的限制

时间:2018-04-15 12:24:52

标签: java google-app-engine google-cloud-platform google-cloud-storage

我们正尝试在App Engine Standard Java 7上将文件上传到Google云端存储。

除了大于10 MB的文件外,一切正常。当我们尝试上传这些文件时,我们得到一个例外:

com.google.appengine.api.urlfetch.RequestPayloadTooLargeException: The request to https://www.googleapis.com/upload/storage/v1/b/filestoragetradeos1/o?projection=full&uploadType=multipart exceeded the 10 MiB limit.
at com.google.appengine.api.urlfetch.URLFetchServiceImpl.convertApplicationException(URLFetchServiceImpl.java:151)
at 

我们用来做的代码:

public Blob createFile(String fileName, InputStream inputStream) throws IOException {

    String bucketName = TSystemUtils.getStorageBucketName();//just a bucket name

    List<Acl> acls = new ArrayList<>();
    acls.add(Acl.of(Acl.User.ofAllAuthenticatedUsers(), Acl.Role.READER));

    byte[] bytes = IOUtils.toByteArray(inputStream);//apache IO library
    Storage storage = StorageOptions.getDefaultInstance().getService();
    Blob blob = storage.create(BlobInfo.newBuilder(bucketName, (UUID.randomUUID() + "/" + fileName)).setAcl(acls).build(), bytes);

    return blob;
}

现在App Engine使用URL Fetch来执行所有HTTP请求,它有一个10 MB Request size limit

有没有办法将大于App Engine Standard Java 7的文件上传到Google云端存储?

1 个答案:

答案 0 :(得分:0)

您可以使用signed URLs从客户端将大型文件上传到云端存储。您的App Engine应用程序将生成签名URL并将其传递给客户端以启动上载。您甚至可以轻松实现resumable uploads