设置内容类型azure blob存储

jogvjijk  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(318)

我目前正在编写一个后端,它接收一个或多个要上载到azure blob存储的图像/视频文件。然而,我正在努力设置文件的内容类型。默认情况下,内容类型设置为“application/octet stream”,但我希望使用file.getcontenttype()方法动态设置它们。
代码如下所示:

public void uploadToContainer(BlobClient blobClient, MultipartFile file) {
        try {
            blobClient.upload(file.getInputStream(), file.getSize());
        } catch (Exception e) {
            //TODO:
            // Better error handling
            e.printStackTrace();
        }
    }

有人知道我怎样才能做到这一点吗?

6tqwzwtp

6tqwzwtp1#

要在上载时设置blob的内容类型,需要使用以下方法: uploadWithResponse(InputStream data, long length, ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, BlobRequestConditions requestConditions, Duration timeout, Context context) 而不是 upload 您当前正在使用的方法。
您将能够使用定义内容类型 BlobHttpHeaders .

相关问题