我用watchbucket命令观看gcs存储桶。之后我正在上传。 watch命令在app引擎上向我的servlet发送通知。 为了确保这一点,我看看日志。但似乎是这样,一些servlet如何在请求后继续获取请求。成功四次,然后获得nullpointer异常。为什么会有这么多请求?
*编辑* 在客户端,我使用meteorJS和Javascript框架。我添加了扩展弹弓来处理上传。 首先,我必须提供像acl,bucket等必要的信息,如下所示:
Slingshot.createDirective('uploadSpotCover', Slingshot.GoogleCloud, {
bucket: 'upload_spot_cover',
GoogleAccessId: 'accessId',
acl: 'project-private',
maxSize: 0,
cacheControl: 'no-cache',
...
}
正如您在第153行中所见,slingshot使用XMLHttpRequest上传到Cloudstorage https://github.com/CulturalMe/meteor-slingshot/blob/master/lib/upload.js#L144
在服务器端,我的Servlet和它的逻辑看起来像这样。
public class Upload extends 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;
}
}
我将特定的服务方法(如保存文件)包装在自己的处理程序中的cloudstorage中。
答案 0 :(得分:0)
因为我不知道你上传了什么,我现在猜。大多数文件上传都是以批量方式上传内容,所以不是一次性整个文件,而是以较小的块为单位,直到一切都结束。这可以解释您获得的多个电话。 你能告诉我们服务器和客户端代码吗?也许这样我们就可以看到问题了。