【发布时间】:2016-06-28 19:10:24
【问题描述】:
我是 Webforms 的 MVC 新手,我正在尝试将图像上传到我的 azure 存储容器。我可以根据需要上传图像并调整其大小,但是有些图像是以错误的方向上传的,例如它们是以横向而不是纵向上传的。
我用谷歌搜索了这个,但似乎找不到其他人有这个问题。
我要上传的代码如下...
提前致谢
string accountName = "xxxxxxxxxxx";
string accountKey = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
try
{
if (file != null)
{
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
CloudBlobClient client = account.CreateCloudBlobClient();
CloudBlobContainer sampleContainer = client.GetContainerReference("uploadedimages");
sampleContainer.CreateIfNotExists();
CloudBlockBlob blob = sampleContainer.GetBlockBlobReference(file.FileName);
using (Stream file1 = file.InputStream)
{
WebImage img = new WebImage(file.InputStream);
if (img.Width > 300)
img.Resize(300, 300);
byte[] bytes = img.GetBytes();
Stream stream = new MemoryStream(bytes);
blob.UploadFromStream(stream);
}
string userIdValue = getUserId();
if (ModelState.IsValid)
{
YourDayEntities6 context = new YourDayEntities6();
context.CreateDayByDate(model.DayDate, blob.Uri.ToString(), model.DayDesc, userIdValue);
}
}
}
catch (Exception e)
{
throw new Exception(string.Format("Error{0}", e.Message));
}
return RedirectToAction("GetAllDaysByDate");
【问题讨论】:
-
好吧,只是为了确保我已经问了一个明显的问题 - 您确定它们最初不是它们上传的格式吗?您如何确定它们的原始方向 - 您是在编辑器中打开它们还是只在资源管理器中查看它们(某些程序会重新定向图像以根据最长轴使它们成为纵向或横向)
-
它们在我的电脑上看起来就像是肖像。我也尝试过从我的手机摄像头上传图像,以纵向拍摄,以纵向存储在我的手机上,但上传时以横向显示..
-
这可能不是一个很好的“方向”定义。尝试在“Paint.net”(此处为 getpaint.net/index.html)之类的程序中打开图像并查看底层宽度/高度 - Paint.net 将以原始格式打开您的图像,并且不会尝试重新定位它。
-
您是否使用一些客户端 (JS) 库来管理 de Uploads?
-
Azure 存储本身对上传的内容一无所知,因此无法执行旋转图片之类的操作。它只是按原样抓取字节并将它们放入 Azure。 @PhillipH 可能有正确的想法来更仔细地检查图像来源。
标签: c# asp.net-mvc azure image-processing azure-blob-storage