Take the 2-minute tour ×

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
so simple.. thanks a lot. fetchData(key, 0, BlobstoreService.MAX_BLOB_FETCH_SIZE-1); gets the whole blob in one call. –  Gaël Oberson Sep 24 '12 at 17:34

Your Answer


