我有以下功能,用于将文件上传到 azure 存储帐户。
如您所见,它不会调整大小等:
public string UploadToCloud(FileUpload fup, string containerName) { // 从连接字符串中检索存储帐户。CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference(containerName);
string newName = "";
string ext = "";
CloudBlockBlob blob = null;
// Create the container if it doesn't already exist.
container.CreateIfNotExists();
newName = "";
ext = Path.GetExtension(fup.FileName);
newName = string.Concat(Guid.NewGuid(), ext);
blob = container.GetBlockBlobReference(newName);
blob.Properties.ContentType = fup.PostedFile.ContentType;
//S5: Upload the File as ByteArray
blob.UploadFromStream(fup.FileContent);
return newName;
}
然后,我拥有了在未托管在 azure 上的网站上使用过的此功能:
public string ResizeandSave(FileUpload fileUpload, int width, int height, bool deleteOriginal, string tempPath = @"~\tempimages\", string destPath = @"~\cmsgraphics\")
{
fileUpload.SaveAs(Server.MapPath(tempPath) + fileUpload.FileName);
var fileExt = Path.GetExtension(fileUpload.FileName);
var newFileName = Guid.NewGuid().ToString() + fileExt;
var imageUrlRS = Server.MapPath(destPath) + newFileName;
var i = new ImageResizer.ImageJob(Server.MapPath(tempPath) + fileUpload.FileName, imageUrlRS, new ImageResizer.ResizeSettings(
"width=" + width + ";height=" + height + ";format=jpg;quality=80;mode=max"));
i.CreateParentDirectory = true; //Auto-create the uploads directory.
i.Build();
if (deleteOriginal)
{
var theFile = new FileInfo(Server.MapPath(tempPath) + fileUpload.FileName);
if (theFile.Exists)
{
File.Delete(Server.MapPath(tempPath) + fileUpload.FileName);
}
}
return newFileName;
}
现在我想做的是尝试将两者合并......或者至少找出一种能够在将图像存储在天蓝色之前调整图像大小的方法。
有人有想法么?