此代码将图像保存到Google云存储中:
byte[] picByte = Base64.decodeBase64(pic);
GcsFileOptions instance = GcsFileOptions.getDefaultInstance();
GcsFilename fileName = new GcsFilename("xxx-app.appspot.com", "/gs/someName.jpg");
GcsOutputChannel outputChannel;
GcsService gcsService = GcsServiceFactory.createGcsService();
outputChannel = gcsService.createOrReplace(fileName, instance);
ByteBuffer a = ByteBuffer.wrap(picByte);
outputChannel.write(a);
outputChannel.close();
但这会保存它而没有
image/jpeg
类型。如何以编程方式添加它,以便将图像直接保存为image / jpeg?
任何帮助将不胜感激!
最佳答案
在GcsFileOptions中。尝试这个:
GcsFileOptions instance = new GcsFileOptions.Builder().mimeType("image/jpeg").build();