1

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 Answer 1

5

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.

1
  • 3
    so simple.. thanks a lot. fetchData(key, 0, BlobstoreService.MAX_BLOB_FETCH_SIZE-1); gets the whole blob in one call. Sep 24, 2012 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.