3
我使用下面的代碼從一個位圖圖像的MemoryStream上傳到我的微軟Azure存儲賬戶:當上傳位圖流Azure存儲,其存儲零/空圖像
MemoryStream memoryStream = new MemoryStream();
img.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
blob.Properties.ContentType = model.File.ContentType;
blob.UploadFromStream(memoryStream);
通過上面的代碼中使用,會發生什麼它是一個上傳空圖像Azure存儲:(!(我發現這個名字,但文件的大小是零!)!
if (model.File != null && model.File.ContentLength > 0)
{
Bitmap original = null;
var name = "newimagefile";
var errorField = string.Empty;
errorField = "File";
name = Path.GetFileNameWithoutExtension(model.File.FileName);
original = Bitmap.FromStream(model.File.InputStream) as Bitmap;
if (original != null)
{
var img = CreateImage(original, model.X, model.Y, model.Width, model.Height);
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("company"); // must always be lowercase
container.CreateIfNotExists();
container.SetPermissions(
new BlobContainerPermissions
{
PublicAccess =
BlobContainerPublicAccessType.Blob
});
CloudBlockBlob blob = container.GetBlockBlobReference(imgName + ".png");
MemoryStream memoryStream = new MemoryStream();
img.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
blob.Properties.ContentType = model.File.ContentType;
blob.UploadFromStream(memoryStream);
}
任何幫助,請!