我使用watchbucket命令觀看gcs存儲桶。之後,我正在上傳。 watch命令會在應用程序引擎上向我的servlet發送通知。爲了確保這一點,我看看日誌。但似乎是這樣,一些servlet如何在請求後繼續獲取請求。成功四次,之後它得到一個空指針異常。爲什麼有這麼多的要求?將圖片上傳到Google雲端存儲後請求過多
*編輯* 在客戶端我使用meteorJS Javascript框架。我添加了擴展彈弓來處理上傳。 首先我必須提供類似的ACL,水桶等這樣的必要信息:
Slingshot.createDirective('uploadSpotCover', Slingshot.GoogleCloud, {
bucket: 'upload_spot_cover',
GoogleAccessId: 'accessId',
acl: 'project-private',
maxSize: 0,
cacheControl: 'no-cache',
...
}
正如你可以看到線153彈弓使用一個XMLHttpRequest上傳到雲端儲存 https://github.com/CulturalMe/meteor-slingshot/blob/master/lib/upload.js#L144
在服務器端我的Servlet和它的邏輯是這樣的。
公共類上傳延伸的HttpServlet {
private BucketNotification notification;
@Override
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
this.notification = getBucketNotification(req);
UploadObject object = new UploadObject(notification);
CloudStorageHandler gcs = new CloudStorageHandler();
BlobstoreHandler bs = new BlobstoreHandler();
ImageTransformHandler is = new ImageTransformHandler();
/** GET DATA FROM GCS **/
byte[] data = gcs.getFileFromGoogleCloudStorage(object.getGcsBucket(), object.getGcsPath());
//BlobKey bk = bs.createBlobKey(object.getGcsBucket(), object.getGcsPath());
/******************/
/** TRANSFORMATION **/
byte[] newImageData = is.resizePicture(data, 1200, 1200, "JPEG", 65, 0.5, 0.5);
/******************/
/** STORE NEW RESIZED FILE INTO GCS BUCKET **/
UploadObject tmp = new UploadObject(object.getGcsPath(), "JPEG", "beispiel", 1200, 1200);
tmp.setData(newImageData);
gcs.saveFileToGoogleCloudStorage(newImageData, "beispiel", object.getGcsPath(), "JPEG", "public-read");
/******************/
/** CREATE SERVING URL via BLOBKEY **/
BlobKey bk_neu = bs.createBlobKey("beispiel", object.getGcsPath());
String servingUrl = is.createServingUrlWithBlobkey(bk_neu);
/******************/
log("Blobkey: "+ bk_neu.getKeyString());
log("url: "+ servingUrl);
res.setStatus(200);
}
private BucketNotification getBucketNotification(HttpServletRequest req) {
BucketNotification notification = null;
String jsonString ="";
try {
jsonString ="";
BufferedReader in = new BufferedReader(new InputStreamReader(req.getInputStream()));
for (String buffer;(buffer = in.readLine()) != null;jsonString+=buffer + "\n");
in.close();
notification = new Gson().fromJson(jsonString, BucketNotification.class);
} catch (IOException e) {
log("Failed to decode the notification: " + e.getMessage());
return null;
}
return notification;
}
}
我包的特定服務的方法,如保存的文件在其自己的處理程序,雲端儲存。
我發現這對[鏈接](https://cloud.google.com/storage/docs/gsutil/addlhelp/RetryHandlingStrategy): [...] 因此,在默認情況下,gsutil可在重試23次1 + 2 + 4 + 8 + 16 + 32 + 60 ...秒約10分鐘。您可以通過編輯.boto配置文件的「[Boto]」部分中的num_retries和max_retry_delay配置變量來調整任何單個重試的重試次數和最大延遲時間。大多數用戶不需要更改這些值。 [...] 所以我去了我的.boto文件,並將num_entries更改爲1,因爲不允許爲0。不幸的是沒有改變 – Laslo89