【问题标题】:How to add the type of image while saving into google storage如何在保存到谷歌存储时添加图像类型
【发布时间】:2017-05-08 14:16:09
【问题描述】:

此代码将图像保存到谷歌云存储:

        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 类型的情况下保存它。 如何以编程方式添加它,以便将图像直接保存为图像/jpeg? 任何帮助将不胜感激!

【问题讨论】:

    标签: java google-app-engine google-cloud-storage


    【解决方案1】:

    它在 GcsFileOptions 中。试试这个:

    GcsFileOptions instance = new GcsFileOptions.Builder().mimeType("image/jpeg").build();
    

    【讨论】:

    • 你的意思是:GcsFileOptions instance = new GcsFileOptions.Builder().mimeType("image/jpeg").build(); ?
    • 啊,是的,就是这样。对不起!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-12
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多