![](/img/trans.png)
[英]How do I print the content of a Stream when the content type is application/octet-stream?
[英]Converting IFormFile to Stream set content type to application/octet-stream
我想將圖像文件上傳到 Azure Blob 容器。 我正在使用 .net 核心 webapi post 方法上傳圖片。上傳成功但內容類型無效,將原始image/jpeg
類型轉換為application/octet-stream
。
[HttpPost]
public async Task<string> Post(IFormFile files)
{
BlobClient blobClient = _containerClient.GetBlobClient(files.FileName);
await blobClient.UploadAsync(files.OpenReadStream());
}
誰能幫助我如何上傳保留原始內容類型的圖像。
提前致謝。
如果要在上傳文件到 Azure blob 時設置 content-type,請參考以下代碼
// I use the sdk Azure.Storage.Blobs
[HttpPost]
public async Task<string> Post(IFormFile file)
{
var connectionString = "the account connection string";
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient containerClient =blobServiceClient.GetBlobContainerClient("test");
await containerClient.CreateIfNotExistsAsync();
BlobClient blobClient = containerClient.GetBlobClient(file.FileName);
BlobHttpHeaders httpHeaders = new BlobHttpHeaders() {
ContentType=file.ContentType
};
await blobClient.UploadAsync(file.OpenReadStream(), httpHeaders);
return "OK";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.