-1

Am having a MVC application wherein user uses the fileupload control and upload the file which is having 30 MB or more into the sql db.

am pretty new to MVC arch., so, am sorry,i may ask stupid questions!

Now, customer says that,end users are facing difficulty in uploading many large files, so, he wanted to optimize , by selecting a folder and fetch all those huge files and insert into the sql db.

multi-file-upload-not-userfriendly

The end users say, they don't wanna click on upload browse & but on on multiple times. instead, they will select a folder - which contain all the files they want- and they will click on a single upload button, it will be uploaded/inserted into db. in the above figure, there are 4 file uploads required. but there may be cases that, thee may be 10 file uploads are required. in this case, end user will not be interested in doing this multifile upload , one by one. these files may be having the size of 10 kb to 100 MB size!

Whats the alternative approach to upload multiple files that also has huge size files into db? after several thoughts, am planning to:

1) Zip file file and load the files into a server's shared location and from there, my code will read files one by one and insert into db
but,can anyone please confirm whether this is the correct approach? I need to create a shared drive in the server -say C:\sharedFolder and then i will prompt the user to browse the multiple files (say file1.txt, file2.xlsx, etc which are having some 40 mb, 50 MB respectively...) and when the click on upload , i will copy the files and dump it into server's sharedfolder location.

what i have tried: I used the fileupload control.

current code in my ABCcontroller.cs file :

   [HttpPost]   
   public ActionResult UploadfilePost(HttpPostedFileBase file)
    {
        string _path;
        try
        {
            if (file.ContentLength > 0)
            {
       string _FileName = Path.GetFileName(file.FileName);
      _path = Path.Combine(Server.MapPath(@"~/App_Data"), _FileName);
          file.SaveAs(_path);
          var tempFileName = Path.GetTempFileName();
                try
                {
       using (var streamReader = new StreamReader(_path))
       using (var streamWriter = new StreamWriter(tempFileName))
                  {
              // code to further manipulate 
                 }
dasarp
  • 123
  • 1
  • 8
  • 3
    *"end users are facing difficulty"* - What difficulty? What isn't working? You're proposing possible solutions and asking for thoughts on those solutions, but never really described the problem being solved. – David May 13 '19 at 13:04
  • 2
    what exact difficulty are you facing when uploading the large files? What is going wrong? How large are we talking? BTW it's not a great idea to store the files themselves within SQL Server, better to put them into some file storage and within SQL Server just hold the path to the file as a string...this will be more efficient. – ADyson May 13 '19 at 13:05
  • 1
    BTW it seems you are simply proposing to replace one upload procedure with another...replacing uploading several large files with uploading a single, even-bigger ZIP file. how would that solve anything, if uploading large items is the issue? If the server is on the same network as these users, it might be better to have the users copy the files directly (via Windows Explorer) to a fileshare location which can be accessed by both the users and the server code, and have the .NET code collect the files from there. – ADyson May 13 '19 at 13:07
  • @ADyson end users say, they dont wanna click on upload browse & but on on multiple times. instead, they will select a folder - which contain all the files they want- and they will click on a single upload button, it will be uploaded/inserted into db. – dasarp May 13 '19 at 13:08
  • why its downvoted!! ohh! – dasarp May 13 '19 at 13:11
  • I didn't downvote, but you can hover your mouse over the downvote button on any question to see the reasons why downvotes are supposed to be given...of course that doesn't mean that the downvoter actually had those reasons in mind, but that's the theory. Beyond that, unless the downvoter adds a comment, you'll never know the true reason. Personally I think your question _was_ unclear until I edited it a moment ago. Whether it shows sufficient research effort is potentially debatable. I'm letting you off since you've mentioned you're a beginner. – ADyson May 13 '19 at 13:12
  • Right so it's a usability issue, not a technical problem? You could use ` – ADyson May 13 '19 at 13:13
  • Possible duplicate of [How to increase the max upload file size in ASP.NET?](https://stackoverflow.com/questions/288612/how-to-increase-the-max-upload-file-size-in-asp-net) – krillgar May 13 '19 at 13:14
  • @krillgar no, that's not the problem...see the comments above, and also the edit I just made. – ADyson May 13 '19 at 13:15
  • 1
    And how is the large file size relevant here...it would be just as inconvenient to keep clicking and selecting if there were 20 tiny 1kb files, surely? – ADyson May 13 '19 at 13:15
  • @ADyson, okay, as you suggested, "it might be better to have the users copy the files directly (via Windows Explorer) to a fileshare location which can be accessed by both the users and the server code, and have the .NET code collect the files from there." i can try this approach. – dasarp May 13 '19 at 13:16
  • @krillgar, i think, the header title was misleading? what my issue was end users doesnt want to click every time on browse and upload ...if the num of files displayed is more than 2. i will put a scree shot of the same – dasarp May 13 '19 at 13:23
  • @user593450 I also went by your line `and upload the file which is having 30 MB or more`, which is over the default size of I believe 4MB. You should be able to upload multiple files if you turn your parameter into an `IEnumerable` of the file object class. I'm still confused with what your problem is, but it sounds like ADyson is closer to being able to help. – krillgar May 13 '19 at 13:29
  • @krillgar , & Adyson, i have updated the question with figure, what the end users are facing now. i hope, i have explained the problem clearly. – dasarp May 13 '19 at 13:33
  • I think the file share suggestion is probably the way to do it, as I suggested earlier. Or you can train the users to create a ZIP file containing all the necessary files, and just upload that single zip file. P.S. I still don't know why you keep on talking about the size of the files...it takes the same amount of time for a user to select a 1MB file as a 100MB file. And it's just as annoying to have to select 10 of them. Since you keep mentioning this topic...are the users really complaining about how long it takes to upload a large file, rather than the length of time to _choose_ the file? – ADyson May 13 '19 at 13:52
  • @ADyson, i was worried about the .net might throw outofmemoryexception if, its taking too much amount of time since because of the bigger size. Please correct me , if i am wrong – dasarp May 14 '19 at 07:09
  • Unless your file is enormous (like hundreds of MB or more) then it's unlikely you'd run out of memory, unless you've set ASP.NET's memory limit very low, or lots of people are trying to upload at once. But regardless of that, a big file will take a long time to upload, yes. – ADyson May 14 '19 at 07:54

1 Answers1

3

You can get multiple files using Request.Files as HttpFileCollectionBase and through iteration you can upload multiple files.

[HttpPost]
        public ActionResult Index(HttpPostedFileBase FileUpload1)
        {
            if (FileUpload1.ContentLength > 0)
            {
                HttpFileCollectionBase files = Request.Files;
                DataTable dt = new DataTable { Columns = { new DataColumn("Path") } };
                for (int i = 0; i < files.Count; i++)
                {
                    HttpPostedFileBase file = files[i];
                    string path = Server.MapPath("~") + "\\Images\\" + file.FileName;
                    dt.Rows.Add(file.FileName);
                    file.SaveAs(path);
                }
                ViewData.Model = dt.AsEnumerable();
            }
            return View();
        }
akshayblevel
  • 194
  • 5