i successfully upload, unzip and save files @ blobstore, but the
images seem to be broken. when i download them from the BlobStore
(simply blobstoreService.serve them) the images have wrong colors, or
displayed partially, or broken in other ways. an attempt to use
ImagesService also throws an exception. i checked the size of the
images before they are zipped and the size of the files unzipped while
written into the blobstore and they look the same. here is my code:
ZipInputStream zis = ...;
ZipEntry entry;
while ((entry =zis.getNextEntry()) !=null)
{
String fileName = entry.getName().toLowerCase();
if(fileName.indexOf(".jpg") != -1 || fileName.indexOf(".jpeg") !=
-1)
{
FileService fileService = FileServiceFactory.getFileService();
String mime = ctx.getMimeType(fileName);//getting mime from
servlet context
AppEngineFile file = fileService.createNewBlobFile(mime,
fileName);
boolean lock = true;
FileWriteChannel writeChannel =
fileService.openWriteChannel(file, lock);
byte[] buffer = new
byte[BlobstoreService.MAX_BLOB_FETCH_SIZE];
while(zis.read(buffer) >= 0)
{
ByteBuffer bb = ByteBuffer.wrap(buffer);
writeChannel.write(bb);
}
writeChannel.closeFinally();
BlobKey coverKey = fileService.getBlobKey(file);
....
}
}
thanks a lot for you time!
does ByteBuffer bb = ByteBuffer.wrap(buffer); writeChannel.write(bb); really handle this correctly?
on the other side...the JPG format shouldn't care about some extra bytes? have forgotten...
int read;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while((read = zis.read()) >= 0)
{
baos.write(read);
if(baos.size() ==
BlobstoreService.MAX_BLOB_FETCH_SIZE)
{
ByteBuffer bb =
ByteBuffer.wrap(baos.toByteArray());
writeChannel.write(bb);
baos = new ByteArrayOutputStream();
}
}
if(baos.size() > 0)
{
ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());
writeChannel.write(bb);
}