ファイルを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;
}
今私がやろうとしているのは、2つをマージしようとすることです...または、少なくとも画像をAzureに保存する前にサイズを変更できる方法を見つけてください。
誰にもアイデアはありますか?