【发布时间】:2011-09-14 19:43:04
【问题描述】:
我正在使用 uploadify 在 ASP.NET MVC3 中上传多个带有进度的图像,我想从 url Gallery/Upload/2 上传到名称为 2 的文件夹和 Gallery/Upload/3 到文件夹 3 等等。我只是不知道怎么做。为了开始上传,我使用了这个sample 并将示例上传脚本修改为:
public string Upload(HttpPostedFileBase fileData)
{
var id = 2;
var fotka = new Photo();
fotka.GalleryId = id;
fotka.Description = fileData.FileName;
fotka.Name = fileData.FileName;
db.Photos.Add(fotka);
db.SaveChanges();
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileData.FileName);
var fileName = Path.GetFileName(fileData.FileName);
string path = Server.MapPath("~/Fotky/") + id.ToString() + "\\" + fileNameWithoutExtension;
// var path = Path.Combine(Server.MapPath("~/Fotky/"), galleryId.ToString(), "/", fileNameWithoutExtension);
using (var input = new Bitmap(fileData.InputStream))
{
int width;
int height;
if (input.Width > input.Height)
{
width = 128;
height = 128 * input.Height / input.Width;
}
else
{
height = 128;
width = 128 * input.Width / input.Height;
}
using (var thumb = new Bitmap(width, height))
using (var graphic = Graphics.FromImage(thumb))
{
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
graphic.DrawImage(input, 0, 0, width, height);
System.IO.Directory.CreateDirectory(Server.MapPath("~/Fotky/") + id.ToString());
using (var output = System.IO.File.Create(path + "_small" + Path.GetExtension(fileName)))
{
thumb.Save(output, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
fileData.SaveAs(path + Path.GetExtension(fileName));
return "ok";
}
如您所见,我默认使用 id 作为 2,但我想从参数中获取它,这可能吗?如何?谢谢
没有人知道答案吗?这对我来说真的很重要
【问题讨论】:
标签: image asp.net-mvc-3 razor uploadify