可以让CloudBlockBlob.UploadFromStreamAsync接受图像的URL吗? 我试图使用LinkedIn basicprofile api来检索用户的图片URL(已经有URL),并且我试图下载然后将图片上传到Azure Blob,就像他们从他们的计算机中选择了一张图片一样。从URL上传图像到Azure Blob存储
这是怎么看起来像现在:
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>
在控制器的方法:
public async Task<ActionResult> UploadPhoto(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var fileExt = Path.GetExtension(file.FileName);
if (fileExt.ToLower().EndsWith(".png") || fileExt.ToLower().EndsWith(".jpg") ||
fileExt.ToLower().EndsWith(".gif"))
{
var user = await GetCurrentUserAsync();
await service.Upload(user.Id, file.InputStream);
}
}
return RedirectToAction("Index");
}
没有,是不可能的,但是从我看到你在表单上载文件不是一个URL,你手动下载的图片? – SilentTremor
是的,这是从您的PC中选择文件并上传它的方法。不知怎的,它应该是可能的。我将尝试从阅读网址和上传该流或其他东西中将它放入流中 – crystyxn
我正在为您创建一些简单的事情, – SilentTremor