gpt4 book ai didi

image - MVC3 uploadify 上传图片到文件夹

转载 作者:行者123 更新时间:2023-12-01 12:59:29 25 4
gpt4 key购买 nike

我正在使用 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,但我想从参数中获取它,这可能吗?如何?谢谢

没有人知道答案吗?这对我来说真的很重要

最佳答案

您可以让您的 Controller 操作将 id 作为操作参数:

public string Upload(HttpPostedFileBase fileData, string id)
{
...
}

然后在配置你的插件时传递这个id:

$("#fileuploader").fileUpload({
'uploader': '@Url.Content("~/Scripts/uploader.swf")',
'cancelImg': '@Url.Content("~/Images/cancel.png")',
'buttonText': 'Select Image',
'script': '@Url.Action("Upload", "Home", new { id = "2" })',
'folder': '@Url.Content("~/uploads")',
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
'multi': true,
'auto': true
});

关于image - MVC3 uploadify 上传图片到文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7422068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com