简体   繁体   English

使用blobstore api从云存储中检索文件的Google App引擎Java错误

[英]google app engine java error using blobstore api to retrieve file from cloud storage

I started running into the 30MB filesize limitation when using the cloud storage client API. 使用云存储客户端API时,我开始遇到30MB文件大小限制。 Upon researching I found the GAE documentation suggesting I use the BlobStore API. 经过研究,我发现GAE文档建议我使用BlobStore API。

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. 没关系,我现在坚持Blob键和我要存储的文件元数据之间的映射。

I then tried to download the file using the blobstoreService.createGsBlobKey() method. 然后,我尝试使用blobstoreService.createGsBlobKey()方法下载文件。 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. 我要传递以下内容:“ / gs /” + bucketName +“ /” + fBlob.getBlobKey())其中fBlob是我的映射对象,其中包含文件信息和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. **编辑**我也尝试使用文件的实际名称而不是Blob键(我不太确定文档要求什么),但是结果是相同的。

The method getBlobKey() does just that. 方法getBlobKey()就是这样做的。 It returns the string I retrieved from the BlobKey.getKeyString() method. 它返回我从BlobKey.getKeyString()方法检索到的字符串。

All seems well until I access the servlet that passes in my parameters to retrieve the file. 一切似乎都很好,直到我访问传递参数的servlet来检索文件。 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. 唯一有问题的指示是通用网页,该网页显示表明发生了500个错误,如果我继续遇到此错误,则会在支持论坛中发布消息。

So here I am :) 所以我在这里:)

Any assistance would be greatly appreciated. 任何帮助将不胜感激。 I would provide more info (ie stack traces) but as I mentioned there aren't any. 我将提供更多信息(即堆栈跟踪),但正如我所提到的,没有任何信息。 Here is a summary of the servlet: 这是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);
}

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. 编辑#2 **经过一番摸索后,我意识到blobstore API生成的键/名称似乎与云存储中实际存储的不相关。

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

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

Resolved ** There is an additional method that is part of the FileInfo object I was using that I had not noticed. 已解决**我正在使用的FileInfo对象中还有一个我没有注意到的附加方法。 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. 此方法称为getGsObjectName(),它返回一个完全映射的字符串,该字符串包含“ / gs /”前缀以及我在云存储中看到的令牌字符串。 This wasn't immediately obvious to me so hopefully this post will save someone else's time in the future. 这对我来说不是立即显而易见的,因此希望这篇文章可以节省其他人的时间。

I think you might have problems with creating the blobKey. 我认为您可能在创建blobKey时遇到问题。 Your fBlob.getBlobKey() already returns blobKey but then you try to put it into another blobKey. 您的fBlob.getBlobKey()已返回blobKey,但随后尝试将其放入另一个blobKey。 Did you try just passing that key into blobstoreService.serve method: 您是否尝试过仅将密钥传递给blobstoreService.serve方法:

blobstoreService.serve(fBlob.getBlobKey(), response);

Also your generic page that you see is the error page served by AppEngine when there is a server error. 当服务器发生错误时,您看到的通用页面也是AppEngine提供的错误页面。 You should check your console for any exceptions. 您应该检查控制台是否有任何异常。 If you're running in production you can check logs in AppEngine console to see the details of the error. 如果您正在生产环境中运行,则可以在AppEngine控制台中查看日志以查看错误的详细信息。

Resolved ** There is an additional method that is part of the FileInfo object I was using that I had not noticed. 已解决**我正在使用的FileInfo对象中还有一个我没有注意到的附加方法。 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. 此方法称为getGsObjectName(),它返回一个完全映射的字符串,该字符串包含“ / gs /”前缀以及我在云存储中看到的令牌字符串。 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. 这是我第一次发布,因此我有点领先。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过Google App Engine(Java)将文件上传到Google云端存储 - Upload file to Google cloud storage from Google App Engine (Java) 尝试从blobstore检索文件并使用谷歌应用引擎将其作为邮件附件发送 - trying to retrieve file from blobstore and send it as mail attachment using google app engine 从App Engine Java将urlconnection文件保存到Google云存储 - saving a urlconnection file to google cloud storage from app engine java 如何在Google App Engine中替代Cloud Storage和BlobStore API处理Blob - How to handle Blobs in Google App Engine alternatively to Cloud Storage and BlobStore API ApplicationError:使用App Engine中的Java远程API将文件发送到Google Cloud Storage时出现10 - ApplicationError: 10 on sending files to Google Cloud Storage using the Java remote API from App Engine 使用Blobstore API将文件上传到Google云端存储 - upload files to google cloud storage using Blobstore API Google App Engine的Blobstore Java API如何工作? - How the Google App Engine's Blobstore Java API works? 使用 Java 通过 Google App Engine 将文件上传到 Google Cloud Storage:(没有这样的文件或目录) - Uploading Files to Google Cloud Storage via Google App Engine using Java: (No such file or directory) 适用于Java和Google云存储的Google App Engine - Google App Engine for Java and Google Cloud Storage 通过Google App Engine(JAVA)将文件(图像或视频)从JSP上传到Google云存储 - Upload File (image or video) from JSP to google cloud storage via Google app engine(JAVA)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM