我想上传一个文件,并将其发送到服务层保存,但我不断找到有关如何控制器获取HTTPPostedFileBase并将其直接保存在控制器。我的服务层对web dll没有依赖性,因此我是否需要将我的对象读入内存流/字节?我应该如何去这个任何指针是极大的赞赏...上传文件并发送到服务层即ie#c#类库
注:文件可以通过PDF,Word,以便我可能还需要检查的内容类型(可能内域名服务层...
代码:
public ActionResult UploadFile(string filename, HttpPostedFileBase thefile)
{
//what do I do here...?
}
编辑:
public interface ISomethingService
{
void AddFileToDisk(string loggedonuserid, int fileid, UploadedFile newupload);
}
public class UploadedFile
{
public string Filename { get; set; }
public Stream TheFile { get; set; }
public string ContentType { get; set; }
}
public class SomethingService : ISomethingService
{
public AddFileToDisk(string loggedonuserid, int fileid, UploadedFile newupload)
{
var path = @"c:\somewhere";
//if image
Image _image = Image.FromStream(file);
_image.Save(path);
//not sure how to save files as this is something I am trying to find out...
}
}
你能告诉我们你的服务层是怎样的吗? – 2011-02-14 11:27:08