簡體   English   中英

無法使用GCS客戶端庫+ java將文件從GAE項目上傳到Google雲存儲

[英]Not able to upload files from GAE project to Google cloud Storage using GCS Client library+java

我正在嘗試使用新的Gcs客戶端庫從我的GAE應用程序上傳圖像/文件到谷歌雲存儲。

這是代碼片段

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>

有人可以幫我解決這個問題。

我也有同樣的問題。 請按照以下說明操作( https://developers.google.com/appengine/docs/java/googlestorage/#Java_Prerequisites

授予您的存儲桶或對象的權限。 要使您的應用程序能夠在存儲桶中創建新對象,您需要執行以下操作:

登錄App Engine管理控制台。 單擊要為雲存儲桶授權的應用程序。 單擊左側“管理”部分下的“應用程序設置”。 復制服務帳戶名稱下的值。 這是您的應用程序的服務帳戶名稱,格式為application-id@appspot.gserviceaccount.com。 如果您使用的是App Engine Premier帳戶,則應用程序的服務帳戶名稱格式為application-id.example.com@appspot.gserviceaccount.com。

使用以下方法授予訪問權限:授予應用程序訪問存儲桶的最簡單方法是使用Google API控制台將應用程序的服務帳戶名稱作為團隊成員添加到包含存儲桶的項目中。(應用程序應該如果需要寫入存儲桶,則具有編輯權限。)有關雲存儲中權限的信息,請參閱范圍和權限。 如果需要,可以向項目團隊添加更多應用。

這個對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM