草庐IT

HttpPostedFileBase

全部标签

c# - 使用 Angular 上传文件时 HttpPostedFileBase 为空

我将Angular与MVC结合使用。当我想上传文件时,HttpPostedFileBase为空。html:Angular:scope.fileInputChanged=function(element){scope.$apply(function(scope){console.log('files:',element.files);_.each(element.files,function(element,index,list){scope.files.push(element);});});}scope.uploadDocuments=function(){varformData=n

c# - 为单元测试创​​建 HttpPostedFileBase 实例

我需要创建一个HttpPostedFileBase类对象的实例并将它传递给一个方法,但我找不到任何方法来实例化它。我正在创建一个测试用例来测试我的文件上传方法。这是我的方法,它接受一个HttpPostedFileBase对象。我需要从我的测试用例类中调用它。我没有使用任何模拟库。有没有简单的方法可以做到这一点?[HttpPost]publicJsonResultAddVariation(HttpPostedFileBasefile,stringname,stringcomment,stringdescription,decimalamount,stringaccountLineType

C# - 我无法引用 HttpPostedFileBase

我在带有CSLA的分布式环境中使用MVC.NET,我可以从我的网络层之一(例如Website.MVC)引用HttpPostedFileBase,但我不能从单独的层(我们称之为OtherLayer.Web)引用HttpPostedFileBase。知道我需要做什么才能调用HttpPostedFileBase吗?我可以在两个层中使用HttpPostedFile-我应该只使用它吗?程序集引用基本相同-在Website.MVC中我有:namespaceWebsite.Mvc.Controllers{usingSystem;usingSystem.Collections;usingSystem.

c# - MVC HttpPostedFileBase 始终为空

我有这个Controller,我想做的是将图像作为[byte]发送到Controller,这是我的Controller:[HttpPost]publicActionResultAddEquipment(Productproduct,HttpPostedFileBaseimage){if(image!=null){product.ImageMimeType=image.ContentType;product.ImageData=newbyte[image.ContentLength];image.InputStream.Read(product.ImageData,0,image.Con

c# - HttpPostedFileBase 与 HttpPostedFileWrapper 的关系

我了解HttpPostedFileBase和HttpPostedFileWrapper之间的关系,就两者的需求而言(即在单元测试/模拟中)。但是,为什么当我在HttpPostedFileBase的返回值上设置断点时,它是否显示为HttpPostedFileWrapper?此外,HttpPostedFileBase没有实现ContentType属性。那么,当我的代码仅引用HttpPostedFileBase而不是HttpPostedFileWrapper时,为什么它会返回一个值?这是什么诡计?编辑#1:感谢@lawliet29的精彩回复。我已经按照建议写出了结构。publicsealed

c# - ASP MVC 文件上传 HttpPostedFileBase 为空

在我的Controller中,因为我希望能够填写有关视频的一些详细信息并实际上传它,Video类不需要实际视频,因为它将被传递到另一个网络服务。publicclassVideoUploadModel{publicHttpPostedFileBasevid{get;set;}publicVideovideoModel{get;set;}}////POST:/Video/Create[HttpPost]publicActionResultCreate(VideoUploadModelVM){if(ModelState.IsValid){db.Videos.AddObject(VM.vide

c# - 在物理路径中使用 HttpPostedFileBase.SaveAs 保存上传的文件

我想通过HttpPostedFileBase.SaveAs()方法将上传的文件保存到物理路径。当我选择物理路径时,出现异常提示路径必须是虚拟的。varfileName=Path.GetFileName(fileurl.FileName);varpath="C:/Projets"+fileName;fileurl.SaveAs(Server.MapPath(path));如何更改我的代码以便能够将文件保存到我想要的任何位置? 最佳答案 Server.MapPath仅适用于作为网站一部分的物理位置。如果您想将文件保存在外部,您可以使用以

c# - MVC3 如何检查 HttpPostedFileBase 是否是图像

我有一个这样的Controller:publicActionResultUpload(intid,HttpPostedFileBaseuploadFile){....}如何确保uploadFile是图像(jpg、png等)我试过using(varbitmapImage=newBitmap(uploadFile.InputStream)){..}如果无法创建bitmapImage,则会抛出ArgumentException。是否有更好的方法,例如查看uploadFile.FileName? 最佳答案 您可以为此检查HttpPosted

c# - MVC3 如何检查 HttpPostedFileBase 是否是图像

我有一个这样的Controller:publicActionResultUpload(intid,HttpPostedFileBaseuploadFile){....}如何确保uploadFile是图像(jpg、png等)我试过using(varbitmapImage=newBitmap(uploadFile.InputStream)){..}如果无法创建bitmapImage,则会抛出ArgumentException。是否有更好的方法,例如查看uploadFile.FileName? 最佳答案 您可以为此检查HttpPosted

c# - 如何创建 HttpPostedFileBase(或其继承类型)的实例

目前我有一个byte[]包含图像文件的所有数据,只是想构建一个HttpPostedFileBase的实例以便我可以使用现有的方法,而不是创建一个新的重载。publicActionResultSave(HttpPostedFileBasefile)publicActionResultSave(byte[]data){//HopeIcanconstructaninstanceofHttpPostedFileBasehereandthenreturnSave(file);//insteadofwritingalotofsimilarcodes} 最佳答案
12