我在應用引擎端點中創建signedURL,然後將其提供給客戶端。但是,當客戶端嘗試使用標識的URL上傳,雲存儲引發以下錯誤使用簽名網址上傳到Google雲端存儲時面臨的問題
Access denied. Anonymous users does not have storage.objects.create access to bucket
App Engine的代碼來生成標識的URL如下:
private String getSignedUrl() {
String encodedUrl = null;
String httpVerb = "PUT";
String contentMD5 = "";
String contentType = "image/rgb";
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, 10);
long expiration = calendar.getTimeInMillis()/1000L;
String canonicalizedExtensionHeaders = "";
String canonicalizedResource =
"/<bucket_name>/<folder_name>/";
String stringToSign =
httpVerb + "\n" + contentMD5 + "\n" + contentType + "\n"
+ expiration + "\n" + canonicalizedExtensionHeaders
+ canonicalizedResource;
AppIdentityService service =
AppIdentityServiceFactory.getAppIdentityService();
String googleAccessId = service.getServiceAccountName();
String baseURL =
"http://storage.googleapis.com/<bucket_name>/<folder-name>/";
SigningResult signingResult =
service.signForApp(stringToSign.getBytes());
String encodedSignature = null;
try {
encodedSignature =
URLEncoder.encode(
new String(Base64.encodeBase64(
signingResult.getSignature(), false),
"UTF-8"), "UTF-8").toString();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
encodedUrl =
baseURL + "?GoogleAccessId=" + googleAccessId + "&Expires="
+ expiration + "&Signature=" + encodedSignature;
return encodedUrl;
}
,並獲得後簽名的URL,我正在使用cURL來測試上傳。我使用以下命令來上傳文件
curl -X PUT -H "Content-Type: multipart/form" -F [email protected]"<file_path>";type=image/rgb <signed_url>
我已經在cURL中嘗試了POST和PUT,結果相同。 我在這裏錯過了什麼嗎?
我不知道這是不是問題,但一般情況下,您可能想要爲HTTPS而不是HTTP簽名URL。 –
即使使用https並根據@Andrei建議刪除文件夾名稱後,我無法從客戶端上傳。 –