如何在 BlobStore 中存储从客户端发送的 Base64 图片

How to store Base64 image sent from client in BlobStore

我对 BlobStore 非常陌生,我从客户端收到了一个 Base64 图像 我是这样转换的:

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

我正在使用球衣 2,我的目标是保存这张照片并稍后获得服务 link blobstoreService.serve

我怎样才能用球衣 2 保存这张图片? 谢谢,

    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();