When you upload files in your Azure Storage account usually all files are uploaded with application/octet-stream
as ContentType. If you just upload .csv files to Azure blob, it doesn't matter. You could change it to text/csv
that you would like.
Modify ContentType:
private static CloudBlockBlob TrySetContentType(CloudBlockBlob blob, string contentType)
{
if (blob.Properties.ContentType.ToLower() != contentType)
{
blob.Properties.ContentType = contentType;
return blob;
}
return null;
}
For more details about ContentType property, see here.
In the latest (12.x+) New Azure SDK for .NET, setting content type needs to be done via BlobHttpHeaders
object.
BlobClient blob = _container.GetBlobClient(fileName);
var blobHttpHeader = new BlobHttpHeaders();
string extension = Path.GetExtension(blob.Uri.AbsoluteUri);
switch (extension.ToLower())
{
case ".jpg":
case ".jpeg":
blobHttpHeader.ContentType = "image/jpeg";
break;
case ".png":
blobHttpHeader.ContentType = "image/png";
break;
case ".gif":
blobHttpHeader.ContentType = "image/gif";
break;
case ".csv":
blobHttpHeader.ContentType = "text/csv";
break;
default:
break;
}
await using (var fileStream = new MemoryStream(fileBytes))
{
var uploadedBlob = await blob.UploadAsync(fileStream, blobHttpHeader);
}