Steps I've followed:
1) Store the images in Blobstore.(This is necessary) 2) Fetch the images from blobstore and save it in GCS bucket.
If I store the image file directly to GCS bucket then it works fine. But I want to fetch it from Blobstore.
Map<String, List<BlobInfo>> blobsData = blobstoreService.getBlobInfos(req);
for (String key : blobsData.keySet())
{
for(BlobInfo blob:blobsData.get(key))
{
byte[] b = new byte[(int)blob.getSize()];
BlobstoreInputStream in = new BlobstoreInputStream(blob.getBlobKey());
in.read(b);
GcsService gcsService = GcsServiceFactory.createGcsService();
GcsFilename filename = new GcsFilename("casfilestorage", blob.getFilename());
GSFileOptionsBuilder builder = new GSFileOptionsBuilder()
.setAcl("public_read")
.setBucket(BUCKET_NAME)
.setKey(blob.getFilename())
.setMimeType(blob.getContentType());
AppEngineFile writableFile = fileService.createNewGSFile(builder.build());
boolean lock = true;
writeChannel = fileService.openWriteChannel(writableFile, lock);
os = Channels.newOutputStream(writeChannel);
UploadOptions uploadOptions = UploadOptions.Builder.withGoogleStorageBucketName("casgaestorage");
//String uploadUrl = blobstoreService.createUploadUrl("/serve", uploadOptions);
os.close();
writeChannel.closeFinally();
in.close();
}
}
Refer below code, Just pass your byte[] to write method: