Here's the code:
這是代碼:
public static String getNotFoundUrl(int size) {
try {
BlobKey blob_key = BLOB_STORE.createGsBlobKey("/gs/web_content/placeholder_img.png");
// Simple Test to make sure blob_key points at the right thing.
byte[] image_data = BLOB_STORE.fetchData(blob_key, 0, 100);
Application.getLogger().warning(new String(image_data));
// This parts works and gets the first 100 bytes.
ServingUrlOptions opts = ServingUrlOptions.Builder.withBlobKey(blob_key);
if(size > 0) opts.imageSize(size);
return IMAGES_SERVICE.getServingUrl(opts);
} catch(IllegalArgumentException e) {
Application.getLogger().warning("Unable to serve placeholder image from Cloud Storage.");
Application.getLogger().warning(e.getMessage());
Application.logException(e);
return "/placeholder_img.png";
}
}
I have also tried using
我也試過用
ServingUrlOptions.Builder.withGoogleStorageFileName
and got the same results.
並得到了相同的結果。
In my mind the blob_key is definitely valid because I'm able to use
在我看來,blob_key絕對有效,因為我可以使用
BlobstoreService.fetchData
to read the first 100 bytes and it's not throwing an exception and is successfully reading the data.
讀取前100個字節並且它不會拋出異常並且正在成功讀取數據。
The only thing that's different about this then other situations is the file I"m trying to access was uploaded via the Cloud Console Web UI rather then through the AppEngine SDK.
與其他情況不同的是,我試圖訪問的文件是通過雲控制台Web UI而不是通過AppEngine SDK上傳的。
0
The problem was permissions. Make sure that your application has permissions to the cloud storage project that you're trying to access.
問題是權限。確保您的應用程序具有您嘗試訪問的雲存儲項目的權限。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/06/18/7252d51c2a401cc77f772b2eae2b9e86.html。