我有以下功能用於將文件上傳到蔚藍存儲帳戶。調整服務器上的映像然後上傳到azure
正如你將看到它沒有那種調整等:
公共字符串UploadToCloud(文件上傳FUP,字符串容器名稱) {// 從連接字符串檢索存儲賬戶。 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;
}
現在我所要做的就是儘量合併兩個......至少工作在將圖像存儲在天藍色之前,可以調整圖像的大小。
任何人有任何想法?