【发布时间】:2013-07-02 14:14:20
【问题描述】:
我正在尝试使用新的 Gcs 客户端库从我的 GAE 应用程序将图像/文件上传到谷歌云存储。
这里是代码sn-p
GcsService gcsService = GcsServiceFactory.createGcsService(new RetryParams.Builder()
.initialRetryDelayMillis(10)
.retryMaxAttempts(10)
.totalRetryPeriodMillis(15000)
.build());
GcsFilename filename = new GcsFilename(BUCKETNAME, FILENAME);
GcsFileOptions options = new GcsFileOptions.Builder().mimeType("text/html").acl("public-read").build();
GcsOutputChannel writeChannel = gcsService.createOrReplace(filename,options);
PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
out.println("The woods are lovely dark and deep.");
out.println("But I have promises to keep.");
out.flush();
writeChannel.waitForOutstandingWrites();
writeChannel.write(ByteBuffer.wrap("And miles to go before I sleep.".getBytes()));
writeChannel.close();
当我查看日志时,我收到这样的 403 错误
Server replied with 403, check that ACLs are set correctly on the object and bucket:
Request: POST https://storage.googleapis.com/<bucket name>/<object name>
x-goog-resumable: start
x-goog-api-version: 2
Content-Type: text/html
x-goog-acl: public-read
no content
Response: 403 with 152 bytes of content
Content-Type: application/xml; charset=UTF-8
Content-Length: 152
Date: Tue, 02 Jul 2013 14:10:02 GMT
Server: HTTP Upload Server Built on Jun 28 2013 13:27:54 (1372451274)
X-Google-Cache-Control: remote-fetch
Via: HTTP/1.1 GWA
<?xml version='1.0' encoding='UTF-8'?><Error><Code>AccessDenied</Code><Message>Access denied.</Message><Details>images2.solestruck.com</Details></Error>
谁能帮我解决这个问题。
【问题讨论】:
-
您是否已将您的应用引擎服务帐户添加到 BUCKETNAME 的权限中?有关如何执行此操作的说明,请参阅 developers.google.com/appengine/docs/java/googlestorage/…。
-
非常感谢,它确实帮助我解决了这个问题。
-
我还有一个小问题。现在,我可以成功上传图片了,当我使用商店管理器查看云存储时,我可以看到“公开分享”没有被选中。我将 acl 设置为“公开阅读”。你能帮我解决这个问题吗?
-
您是否设置了存储桶 acl 而不是对象 acl?经理显示完整的 acl 是什么?
-
我正在尝试仅通过此语句设置 acl "GcsFileOptions options = new GcsFileOptions.Builder().mimeType("text/html").acl("public-read").build() ;"如何为对象设置acl。
标签: java google-app-engine google-cloud-storage