0
votes

I am currently writing a backend which takes in one or many image/video-files to be uploaded into Azure Blob Storage. I am however struggling to set the Content-Type of the files. The Content-Type is by default set to be "application/octet-stream", but I want to dynamically set them by using the file.getContentType() method.

The code looks like this:

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

Does anyone know how I can accomplish this?

1

1 Answers

0
votes

To set content type of a blob at the time of uploading, you will need to use the following method: uploadWithResponse(InputStream data, long length, ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, BlobRequestConditions requestConditions, Duration timeout, Context context) instead of upload method that you're using currently.

You will be able to define content type using BlobHttpHeaders.