无法发布到Azure存储吗?无效的路径错误 [英] Cant post to Azure storage? Invalid Path error
问题描述
我正在尝试添加这样接收到的图像.
I am trying to add an image I am receiving like this.
[FunctionName("Imageupload")]
public static async System.Threading.Tasks.Task<HttpResponseMessage> RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "HttpTriggerCSharp/name/{name}")]HttpRequestMessage req, string name, TraceWriter log)
{
//Check if the request contains multipart/form-data.
if (!req.Content.IsMimeMultipartContent())
{
return req.CreateResponse(HttpStatusCode.UnsupportedMediaType);
}
var storageConnectionString = "XXXXXXXXXXXXXXXXXXX";
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
log.Info(storageConnectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("temporary-images");
// Create the container if it doesn't already exist.
container.CreateIfNotExists();
//Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("images");
try
{
string root = blockBlob.Uri.AbsoluteUri;
var provider2 = new MultipartFormDataStreamProvider(root);
await req.Content.ReadAsMultipartAsync(provider);
}
catch (StorageException e)
{
return req.CreateErrorResponse(HttpStatusCode.NotFound,e.Message);
}
}
我使用的路径是正确的,它指向存储容器.
The path I am using is right as I checked it and it points to the storage container.
如何将收到的图像发送到Azure存储?
How Can I send the images I receive to Azure storage?
我收到以下错误消息:不支持路径格式.
I recieve the error that the path's format is not supported.
我的路径如下:" https://XXXXXXXXXXX.blob. core.windows.net/temporary-images/images "
推荐答案
我收到不支持路径格式的错误.
I recieve the error that the path's format is not supported.
由于MultipartFormDataStreamProvider
请求将本地文件路径作为参数,因此blob地址http/https无效.
As MultipartFormDataStreamProvider
requests local file path as parameter, so blob address http/https is not valid.
如果要将多个文件上传到Azure存储容器,请尝试使用req.Content.ReadAsMultipartAsync();
和blockBlob.UploadFromStream(stream);
将文件上传到Azure存储Blob.我做了一个演示,它可以正常工作.
If you want to upload mutiple files to Azure storage container, please have try to use req.Content.ReadAsMultipartAsync();
and blockBlob.UploadFromStream(stream);
to upload file to azure storage blob. I do a demo, it works correctly on my side.
if (!req.Content.IsMimeMultipartContent())
{
return req.CreateResponse(HttpStatusCode.UnsupportedMediaType);
}
var storageConnectionString = "connection string";
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
log.Info(storageConnectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("temporary-images");
container.CreateIfNotExists();
try
{
var filesReadToProvider = await req.Content.ReadAsMultipartAsync();
foreach (var stream in filesReadToProvider.Contents)
{
var blobName = stream.Headers.ContentDisposition.FileName.Trim('"');
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);
blockBlob.UploadFromStream(stream.ReadAsStreamAsync().Result);
}
}
catch (StorageException e)
{
return req.CreateErrorResponse(HttpStatusCode.NotFound, e.Message);
}
这篇关于无法发布到Azure存储吗?无效的路径错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!