This is why I started this post. I can't iterate the blobdata or fetch the
blob data for image transformation because I can't figure out the correct
length of the blob.
private byte[] getImageBytes(BlobData blobData) {
if (blobData == null) {
return null;
}
BlobKey blobKey = new BlobKey(blobData.getKey());
BlobInfo bi = blobInfofactory.loadBlobInfo(blobKey);
if (blobKey == null) {
return null;
}
long size = bi.getSize();
ByteArrayOutputStream out = new ByteArrayOutputStream();
long filesize = blobData.getSize();
int chunkSize = 1024;
long offset = 0;
while (offset < filesize) {
long limit = offset + chunkSize - 1;
if (filesize < limit) {
limit = filesize;
}
System.out.println("offset=" + offset + " limit=" + limit + " size=" +
size);
byte[] b = null;
try {
b = blobstoreService.fetchData(blobKey, offset, limit);
} catch (Exception e) {
e.printStackTrace();
}
try {
out.write(b);
} catch (IOException e) {
e.printStackTrace();
return null;
}
offset += chunkSize;
if (offset > filesize) {
offset = filesize;
}
}
byte[] filebytes = out.toByteArray();
System.out.println("getImageBytes(): filebytes size: " + filebytes.length +
" blobData.size=" + blobData.getSize());
return filebytes;
}
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.