Java 如何在保存到google存储时添加图像类型
此代码将图像保存到google云存储:Java 如何在保存到google存储时添加图像类型,java,google-app-engine,google-cloud-storage,Java,Google App Engine,Google Cloud Storage,此代码将图像保存到google云存储: byte[] picByte = Base64.decodeBase64(pic); GcsFileOptions instance = GcsFileOptions.getDefaultInstance(); GcsFilename fileName = new GcsFilename("xxx-app.appspot.com", "/gs/someName.jpg"); GcsOutput
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();
您的意思是:GcsFileOptions实例=新建GcsFileOptions.Builder.mimeTypeimage/jpeg.build?啊,是的,就这样。很抱歉