Search code examples
javagoogle-app-enginejerseyblobblobstore

How to store Base64 image sent from client in BlobStore


I am extremely new to BlobStore, I am receiving a Base64 image from the client I am converting it like this:

byte [] picByte = Base64.decodeBase64(pic);
Blob blob = new Blob(picByte);

I am using jersey 2 and my goal is to save this picture and later get the serving link blobstoreService.serve

How can I save this image with jersey 2? Thanks,


Solution

  •     byte[] picByte = Base64.decodeBase64(pic);
        GcsFileOptions instance = new GcsFileOptions.Builder().mimeType("image/jpeg").build();
        GcsFilename fileName = new GcsFilename("xxx-app.appspot.com", "someName.jpg");
        GcsOutputChannel outputChannel;
        GcsService gcsService = GcsServiceFactory.createGcsService();
        outputChannel = gcsService.createOrReplace(fileName, instance);
        ByteBuffer a = ByteBuffer.wrap(picByte);
        outputChannel.write(a);
        outputChannel.close();