这在这里可能有点太具体了,我可能需要联系redactor支持,但我在这里看到了其他关于redactor的问题,所以我想我应该试一试……
好的..。
所以我试着按照下面的例子上传图片。
http://imperavi.com/redactor/docs/images/
我的客户端代码...
$("textarea").redactor({
focus: true,
imageUpload: '/MyController/UploadImage'
});我的MVC控制器动作看起来像这样...
public JsonResult UploadImage(object image)
{
// Do something with whatever that was i got from redactor
var result = new { filelink = "" };
return Json(result);
}问题是。redactor到底给了我什么?是整个文件吗?一大块?我不能说,因为对象根本没有类型信息,而且原始的post信息似乎太少,实际上不是一个完整的图像文件。
有没有人有这方面的经验/以前真的做过?我真的不想在我的服务器上为这个1函数设置php。
编辑:好的,再深入一点就会发现,如果我拉出底层的Request对象,它有一个files属性,该属性显然包含了我发布的图像文件。我想我也许能从这里弄清楚。
在我准备好代码块的地方,我会把它作为答案发布。
发布于 2013-03-28 09:43:21
好的嗯..。我想我在那儿..。这需要一些清理,我不希望你们理解我的自定义DMS代码的引擎盖下发生了什么,但只要假设它接受流并返回一个FileInfo对象,理论上这应该也适用于您……
public ActionResult Upload()
{
// this object is specific to my system but all it does is
// stream the file to a path on the server (code not needed for this Q)
var dmsService = _kernel.Get<IDMSFileSystemService>();
List<FileInfo> savedFiles = new List<FileInfo>();
for (int i = 0; i < Request.Files.Count; i++)
{
var file = Request.Files[i];
using (file.InputStream)
{
savedFiles.Add(dmsService.AddFromStream(file.InputStream, file.FileName);
}
}
var result = savedFiles.Select(f => new { filelink = f.Path}).ToArray();
return Json(result);
}令人惊讶的简单的权利... :)
发布于 2013-04-04 04:30:38
您正在接收一个HttpPostedFileBase对象。下面是我的实现:
jQuery:
$('#blog-post').redactor(
{
imageUpload: '/blog/images/',
imageGetJson: '/images/locations/blogs/'
});然后在控制器中:
public ActionResult Images(HttpPostedFileBase file)
{
// Verify that the user selected a file
if( file != null && file.ContentLength > 0 )
{
// extract only the fielname
var fileName = Path.GetFileName( file.FileName );
// store the file
var path = Path.Combine( ImageLocation.BlogPicturePath, fileName );
file.SaveAs( path );
}
return Json( new { filelink = ImageLocation.BlogPictureUrl + "/" + file.FileName } );
}https://stackoverflow.com/questions/15672190
复制相似问题