httppostedfilebase

HttpPostedFileBase's relationship to HttpPostedFileWrapper

无人久伴 提交于 2019-11-28 06:59:03
I understand the relationship between HttpPostedFileBase and HttpPostedFileWrapper , in terms of the need for both of them (i.e. in unit testing/mocking). But why, when I put a breakpoint on the return for HttpPostedFileBase , does it show it as HttpPostedFileWrapper ? Furthermore, HttpPostedFileBase doesn't implement the ContentType property. So why does it return a value when my code only references HttpPostedFileBase , and not HttpPostedFileWrapper ? What kind of trickery is this? Edit #1: Thanks for the great reply @lawliet29. I have written out the structure as suggested. public sealed

How do you convert a HttpPostedFileBase to an Image?

岁酱吖の 提交于 2019-11-28 03:15:35
I am using ASP.NET MVC and I've an action that uploads the file. The file is being uploaded properly. But I want width and height of the image. I think I need to convert the HttpPostedFileBase to Image first and then proceed. How do I do that? And please let me know if there is another better way to get the width and height of the image. I use Image.FromStream to as follows: Image.FromStream(httpPostedFileBase.InputStream, true, true) Note that the returned Image is IDisposable . You'll need a reference to System.Drawing.dll for this to work, and Image is in the System.Drawing namespace.

Mocking HttpPostedFileBase and InputStream for unit-test

喜你入骨 提交于 2019-11-27 22:48:30
I want to test the following line of code: ... Bitmap uploadedPicture = Bitmap.FromStream(model.Picture.InputStream) as Bitmap; ... Picture is a property in my model type HttpPostedFileBase. So I would like to mock a HttpPostedFileBase property for unit-testing: model.Picture = new Mock<HttpPostedFileBase>().Object; No problem at all. Now I have to mock the InputStream, otherwise it's null: model.Picture.InputStream = new Mock<Stream>().Object; This isn't working as the InputStream is read-only (hasn't a setter method): public virtual Stream InputStream { get; } Is there a good and clean way

MVC 6 HttpPostedFileBase?

我只是一个虾纸丫 提交于 2019-11-27 18:43:57
I am attempting to upload an image using MVC 6 ; however, I am not able to find the class HttpPostedFileBase . I have checked the GitHub and did not have any luck. Does anyone know the correct way to upload a file in MVC6 ? MVC 6 used another mechanism to upload files. You can get more examples on GitHub or other sources . Just use IFormFile as a parameter of your action or a collection of files or IFormFileCollection if you want upload few files in the same time: public async Task<IActionResult> UploadSingle(IFormFile file) { FileDetails fileDetails; using (var reader = new StreamReader(file

File upload in MVC when used in bootstrap modal returns null

僤鯓⒐⒋嵵緔 提交于 2019-11-27 06:50:52
问题 I'm trying to upload images to my application but it always returns null. I'm unable to find the issue here. Can you help me out? Here's my code. Model [Table("Slider")] public partial class Slider : BaseModel { [Required] [StringLength(200)] public string FileName { get; set; } [StringLength(200)] public string Title { get; set; } [StringLength(1000)] public string Description { get; set; } public int? Order { get; set; } } [NotMapped] public class SliderImage : Slider { public

HttpPostedFileBase's relationship to HttpPostedFileWrapper

南笙酒味 提交于 2019-11-27 01:39:12
问题 I understand the relationship between HttpPostedFileBase and HttpPostedFileWrapper , in terms of the need for both of them (i.e. in unit testing/mocking). But why, when I put a breakpoint on the return for HttpPostedFileBase , does it show it as HttpPostedFileWrapper ? Furthermore, HttpPostedFileBase doesn't implement the ContentType property. So why does it return a value when my code only references HttpPostedFileBase , and not HttpPostedFileWrapper ? What kind of trickery is this? Edit #1:

Mocking HttpPostedFileBase and InputStream for unit-test

感情迁移 提交于 2019-11-26 23:14:19
问题 I want to test the following line of code: ... Bitmap uploadedPicture = Bitmap.FromStream(model.Picture.InputStream) as Bitmap; ... Picture is a property in my model type HttpPostedFileBase. So I would like to mock a HttpPostedFileBase property for unit-testing: model.Picture = new Mock<HttpPostedFileBase>().Object; No problem at all. Now I have to mock the InputStream, otherwise it's null: model.Picture.InputStream = new Mock<Stream>().Object; This isn't working as the InputStream is read

ASP.NET MVC 4 C# HttpPostedFileBase, How do I Store File

旧巷老猫 提交于 2019-11-26 20:31:57
Model public partial class Assignment { public Assignment() { this.CourseAvailables = new HashSet<CourseAvailable>(); } public string AssignmentID { get; set; } public Nullable<System.DateTime> SubmissionDate { get; set; } public string Status { get; set; } public Nullable<decimal> Mark { get; set; } public string Comments { get; set; } public string FileLocation { get; set; } public virtual ICollection<CourseAvailable> CourseAvailables { get; set; } }} Controller public ActionResult Create(Assignment assignment) { if (ModelState.IsValid) { db.Assignments.Add(assignment); db.SaveChanges();

MVC 6 HttpPostedFileBase?

点点圈 提交于 2019-11-26 19:34:43
问题 I am attempting to upload an image using MVC 6 ; however, I am not able to find the class HttpPostedFileBase . I have checked the GitHub and did not have any luck. Does anyone know the correct way to upload a file in MVC6 ? 回答1: MVC 6 used another mechanism to upload files. You can get more examples on GitHub or other sources. Just use IFormFile as a parameter of your action or a collection of files or IFormFileCollection if you want upload few files in the same time: public async Task

ASP.NET MVC posted file model binding when parameter is Model

二次信任 提交于 2019-11-26 15:48:42
问题 Is there any way to get posted files ( <input type="file" /> ) to take part in model binding in ASP.NET MVC without manually looking at the request context in a custom model binder, and without creating a separate action method which only takes a posted file as input? I would have thought that this would work: class MyModel { public HttpPostedFileBase MyFile { get; set; } public int? OtherProperty { get; set; } } <form enctype="multipart/form-data"> <input type="file" name="MyFile" /> <input