问题
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