使用blobstore api从云存储中检索文件的Google App引擎Java错误 [英] google app engine java error using blobstore api to retrieve file from cloud storage

查看:144
本文介绍了使用blobstore api从云存储中检索文件的Google App引擎Java错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用云存储客户端API时,我开始遇到30MB文件大小限制.经过研究,我发现GAE文档建议我使用BlobStore API.

I started running into the 30MB filesize limitation when using the cloud storage client API. Upon researching I found the GAE documentation suggesting I use the BlobStore API.

我创建了一个初始测试以上传到我的云服务中的存储桶.我注意到的一件事是文件名丢失了,而是使用了一个密钥.没关系,我现在坚持Blob键和要存储的文件元数据之间的映射.

I created an initial test to upload to a bucket in my cloud service. One thing I notice is that the filenames are lost and instead a key is used. No biggie, I now persist the mapping between the blob key and the file metadata I want to store.

然后,我尝试使用blobstoreService.createGsBlobKey()方法下载文件.我要传递以下内容: "/gs/" + bucketName +"/" + fBlob.getBlobKey()),其中fBlob是我的映射对象,其中包含文件信息和Blob键.

I then tried to download the file using the blobstoreService.createGsBlobKey() method. I am passing in the following: "/gs/" + bucketName + "/" + fBlob.getBlobKey()) where fBlob is my mapping object that contains the file info and the blob key.

**编辑**我也尝试使用文件的实际名称代替blob键(我不太确定文档要求什么),但是结果是相同的.

** Edit ** I also tried using the actual name of the file instead of the blob key (I wasn't quite sure what the documentation was asking for) but the results were the same.

方法getBlobKey()就是这样做的.它返回我从BlobKey.getKeyString()方法检索到的字符串.

The method getBlobKey() does just that. It returns the string I retrieved from the BlobKey.getKeyString() method.

一切似乎都很好,直到我访问传递参数的servlet来检索文件.我所有的日志转储看起来都很不错.使事情更令人沮丧的是,日志中没有任何错误.唯一有问题的迹象是通用网页,该网页显示已发生500错误,如果我继续遇到此错误,则会在支持论坛中发布消息.

All seems well until I access the servlet that passes in my parameters to retrieve the file. All of my log dumps look good. Making things more frustrating is that there aren't any errors in the logs. The only indication there is a problem is the generic web page that shows indicating a 500 error has occurred and to post a message in the support forum if I continue to encounter this error.

所以我在这里:)

任何帮助将不胜感激.我会提供更多信息(即堆栈跟踪),但如上所述.这是servlet的摘要:

Any assistance would be greatly appreciated. I would provide more info (i.e. stack traces) but as I mentioned there aren't any. Here is a summary of the servlet:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws     ServletException, IOException {
    String iopsKey = request.getParameter("iopsId");
    String itemId = request.getParameter("itemId");
    String digitalId = request.getParameter("resourceId");

    Logger.getAnonymousLogger().info("Site Id: " + iopsKey);
    Logger.getAnonymousLogger().info("Item Id: " + itemId);
    Logger.getAnonymousLogger().info("Digital Good Id: " + digitalId);

    final DigitalResource resource = delegate.getDigitalResource(iopsKey, itemId, digitalId);
    Logger.getAnonymousLogger().info("Contents of Digital Resource: " + resource);

    FileBlobMap fBlob = delegate.findBLOBByFilename(resource.getInternalName());
    Logger.getAnonymousLogger().info("Contents of FileBlogMap: " + fBlob);

    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
    BlobKey blobKey = blobstoreService.createGsBlobKey("/gs/vendor-imports/" + fBlob.getBlobKey());

    blobstoreService.serve(blobKey, response);
}

编辑#2 ** 经过一番摸索后,我意识到由blobstore API生成的键/名称似乎与实际存储在云存储中的内容不相关.

Edit #2 ** After some playing around I realize that the key/name generated by the blobstore API does not seem to correlate with what is actually stored in the cloud storage.

在使用blobstore api时,我仅知道两个对映射回存储文件有用的字段:blob密钥对象的密钥字符串和文件的实际名称.但是,在云存储中创建的名称/密钥值是另一个密钥字符串,似乎与任何AFAIK都不匹配.

When using the blobstore api I am aware of only 2 fields that would be useful in mapping back to the stored file: The key string from the blob key object and the actual name of the file. However, the name/key value that is created in the cloud storage is yet another key string and doesn't seem to match anything AFAIK.

现在,如果我从云存储中复制密钥/名称并将其硬编码到我的通过DataStore Viewer存储文件名/blobkey映射的对象,则一切正常!因此,似乎在云存储中的引用与我在回叫处理程序中获得的内容之间存在脱节.

Now if I copy the key/name from the cloud store and hard code it to my object that stores the filename/blobkey mapping via the DataStore Viewer then everything works! So it seems that there is a disconnect between the reference in the cloud store and what I am getting in my call back handler.

已解决** 还有一个其他方法,它是我正在使用的FileInfo对象的一部分,但没有注意到.此方法称为getGsObjectName(),它返回一个完全映射的字符串,该字符串包含"/gs/"前缀以及我在云存储中看到的令牌字符串.这对我来说并不是立即显而易见的,因此希望这篇文章可以节省其他人的时间.

Resolved ** There is an additional method that is part of the FileInfo object I was using that I had not noticed. This method is called getGsObjectName() and it returns a fully mapped string that includes the "/gs/" prefix already along with the token string I see in the cloud store. This wasn't immediately obvious to me so hopefully this post will save someone else's time in the future.

推荐答案

已解决**我使用的FileInfo对象中有一个我没有注意到的附加方法.此方法称为getGsObjectName(),它返回一个完全映射的字符串,该字符串包含"/gs/"前缀以及我在云存储中看到的令牌字符串.这对我来说并不是立即显而易见的,因此希望这篇文章可以节省其他人的时间.

Resolved ** There is an additional method that is part of the FileInfo object I was using that I had not noticed. This method is called getGsObjectName() and it returns a fully mapped string that includes the "/gs/" prefix already along with the token string I see in the cloud store. This wasn't immediately obvious to me so hopefully this post will save someone else's time in the future.

很抱歉,如果我的格式已关闭并且我在多个位置都有解决方案".这是我第一次发布,所以我有点领先.

Sorry if my formatting is off and the fact that I have "solutions" in multiple places. This is my first time posting so and I got a little ahead of myself.

这篇关于使用blobstore api从云存储中检索文件的Google App引擎Java错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆