【发布时间】:2017-01-06 19:54:51
【问题描述】:
public class StorageService
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=removed for this post");
public async Task Upload(string id, Stream data)
{
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("images");
await container.CreateIfNotExistsAsync();
container.SetPermissions(
new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
});
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference(id);
await blockBlob.UploadFromStreamAsync(data, data.Length);
}
public async Task UploadBlogPhoto(string id, Stream data)
{
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
await container.CreateIfNotExistsAsync();
container.SetPermissions(
new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
});
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference(id);
await blockBlob.UploadFromStreamAsync(data, data.Length);
}
}
所以我有了 StorageServices 类,我使用第一种方法 Upload 来上传用户的个人资料图片。
这里是标记:
using (Html.BeginForm("UploadPhoto", "Manage", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="browseimg">
<input type="file" class="display-none" name="file" id="files" onchange="this.form.submit()" />
</div>
}
<button class="btn btn-primary width-100p main-bg round-border-bot" id="falseFiles">
Upload billede
</button>
这是用于上传照片的 summernote 按钮。帖子上传到数据库。但是,有没有办法将文本上传到数据库并将图像上传到 Azure blob?我需要先上传图片,然后将azure blob的URL添加到summernote中来异步执行吗?可以吗?
【问题讨论】:
-
我没有使用 Summernote,所以我不知道它是如何工作的,但考虑到 Azure Blob Storage 和 Summernote 是两个不同的数据存储,您需要执行两个操作:一个是上传 blob,另一个是然后写入这个 Summernote 数据库。尽管您只能在上传功能中执行这两种操作。首先将图片上传到blob存储中,等待它完成,然后插入文本。
标签: azure file-upload summernote