How to retrieve a byte array from the blobstore?

℡╲_俬逩灬. 提交于 2019-12-11 10:53:11

问题


I read the docs, googled around, but still cannot figure how to read a blob as a byte array.

I'm able to generate PDF files and store them in the blobstore. I can also serve these blobs for download using serve(), no problems. All this is working fine.

Now I want to retrieve one of these blobs, and read it as a byte array to pass it to the Mail API, for sending as Mime attachment. The Mail API accepts only byte arrays as attachment data, as I understood.

I saw the read() method of the BufferedInputStream, but it proposes to fetch n bytes. I need to read the full blob at once. I don't know its length before reading it.


回答1:


Like this:

byte[] myFile = blobstoreService.fetchData(blobKey, index, index + batchSize);

Basically you start at index=0 and you loop through this blob until you get an array which is shorter than your batch size.



来源:https://stackoverflow.com/questions/12556892/how-to-retrieve-a-byte-array-from-the-blobstore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!