我正在尝试使用以下代码在上传到 Azure blob 之前使用 WebImage 帮助程序调整图像大小,但出现此错误:
cannot convert from 'system.web.helpers.webimage' to 'system.io.stream'
代码如下:
public async Task<string> UploadPropertyImageAsync(HttpPostedFileBase imageToUpload)
{
string imageFullPath = null;
if (imageToUpload == null || imageToUpload.ContentLength == 0 || imageToUpload.ContentLength >= 8388608)
{
return null;
}
//Image img = System.Drawing.Image.FromStream(imageToUpload);
WebImage img = new WebImage(imageToUpload.InputStream);
if (img.Width > 1000)
img.Resize(1000, 1000);
try
{
CloudStorageAccount cloudStorageAccount = ConnectionString.GetConnectionString();
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("property");
if (await cloudBlobContainer.CreateIfNotExistsAsync())
{
await cloudBlobContainer.SetPermissionsAsync(
new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
}
);
}
string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(img.FileName);
CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(imageName);
cloudBlockBlob.Properties.ContentType = img.ContentType;
await cloudBlockBlob.UploadFromStreamAsync(img);
知道我哪里出错了吗?