storage icon indicating copy to clipboard operation
storage copied to clipboard

Content-type(media type) inference of Azure blob storage?

Open hmqgg opened this issue 4 years ago • 9 comments

Now the blob storage client upload files with content-type application/octet-stream.

Azure Storage Explorer supports determining content-type while uploading, how about implement this?

hmqgg avatar Mar 05 '20 05:03 hmqgg

Hi. Do you mean by file extension or explicitly specifying?

aloneguid avatar Mar 05 '20 13:03 aloneguid

By file extension.

hmqgg avatar Mar 06 '20 01:03 hmqgg

Just a reminder :) @aloneguid

hmqgg avatar Mar 15 '20 12:03 hmqgg

If this cannot be done via the file extension, would it be possible to allow it to be either specified when writing, or even by updating the properties?

blob.Properties["ContentType"] = "image/png";
await _blobStorage.SetBlobAsync(blob);

james-heppinstall avatar Apr 29 '20 16:04 james-heppinstall

Sorry busy times. I'm not sure that setting properties on blob will work when saving it, I need to check how that works across implementations - we don't want it to be Azure only. It might be worth adding a property to Blob class itself, like Size one. Let me come back to you on that. Are you happy to contribute code?

I also have cross platform content type detection code which I can add to this library, it's already tested.

aloneguid avatar Apr 29 '20 19:04 aloneguid

Hi Ivan, I am happy to contribute where I can. If you point me in the right direction I will make some time.

james-heppinstall avatar Apr 29 '20 20:04 james-heppinstall

@aloneguid Is this still in the work ? The current implementation still uploads files with content type being "application/octet-stream". I would also be interested in the cross-platform content type detection ! :)

yannickrondeau avatar Nov 27 '21 04:11 yannickrondeau

Sorry forgot about it ) I took mime type database from Linux, it's easily parseable. I can forward it to you if you want to take on the PR?

aloneguid avatar Nov 27 '21 09:11 aloneguid

@aloneguid I would love to contribute to the project down the line. At the moment, I simply define the content-type within my controller, which isn't that pretty, but works (when I get back the files).

var contentTypeProvider = new FileExtensionContentTypeProvider();
if (!contentTypeProvider.TryGetContentType(fileDto.FileName, out String contentType))
{
    contentType = "application/octet-stream"; // fallback
}

However, if you want to share the mime database you have and let me know where you would see this implementation within the project, I might have time during holidays to look at it.

yannickrondeau avatar Nov 29 '21 01:11 yannickrondeau