Drag and Drop error

Hello,
I try to save one or more file with drag and drop functionality.

Without drag and drop I save one or more files. 
My code is below:

View:
                @{Html.EJ().Uploadbox("uploadbox")
                              .AllowDragAndDrop(true)
                              .AsyncUpload(false)
                              .UploadBoxDialogText(p => p.Name("Nome File").Title("Caricamento File").Status("Stato").Size("Dimensione"))
                              .ShowFileDetails(true)
                              .AutoUpload(false)
                              .ExtensionsAllow(".pdf")
                              .ShowBrowseButton(false)
                              .DropAreaHeight("300px")
                              .DropAreaWidth("480px")
                              .DropAreaText("Trascina i file o clicca qui")
                              .UploadBoxButtonText(p => p.Cancel("Annulla"))
                              .UploadBoxCustomFileDetails(p => p.Status(false))
                              .CssClass("custom")
                              .ClientSideEvents(eve => eve.FileSelect("OnSelect"))
                              .Render();}

Controller:

        public async Task<ActionResult> Upload(IFormCollection collection)
        {
                         foreach (FormFile file in collection.Files)
                        {
                              //content length is 0 with drag and drop
                         }

          }



5 Replies

PO Prince Oliver Syncfusion Team February 2, 2018 06:04 AM UTC

Hi Davide,   
  
Thank you for contacting Syncfusion Support.   
  
We have checked your code, it seems that you have used a “FormCollection” to receive the file in the controller for the synchronous upload. By changing it to the “IEnumerable<HttpPostedFileBase>” you can access the file in the controller. Also, make sure that Upload box's ID and the method’s argument name are same. Refer to the following code.   

public ActionResult SaveDefault(IEnumerable<HttpPostedFileBase> uploadbox) 
{   // make sure that Upload box's ID and the argument's name are same 
    foreach (var file in uploadbox) 
    { 
        var content = file.ContentLength; // Access content length here 
        var fileName = Path.GetFileName(file.FileName); 
        var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName); 
        file.SaveAs(destinationPath); 
    } 
    return View("FileUploadFeatures"); 
} 

We have prepared a sample using your provided code, please find the sample at the following location: http://www.syncfusion.com/downloads/support/forum/135715/ze/UploadDragSample11776668 

Regards, 
Prince 



DD Davide D Angelo February 5, 2018 09:53 AM UTC

Hello Prince,
thank you for your answer.

I try your solution and it seems it does not work.

Your example seems to use asp net mvc <= 5.0, while I'm using Asp Net Core.

Thank you,
Davide


PO Prince Oliver Syncfusion Team February 6, 2018 08:51 AM UTC

Hi Davide,    
   
Thank you for your update. 

As per your requirement, we have prepared Uploadbox sample for ASP.NET Core platform. You can use the following controller code to access the save files in the controller, kindly refer to the following code snippet. 

[Controller] 
[HttpPost] 
public IActionResult UploadFiles(IList<IFormFile> UploadDefault) 
{ 
    long size = 0; 
    foreach (var file in UploadDefault) 
    { 
        var filename = ContentDispositionHeaderValue 
                        .Parse(file.ContentDisposition) 
                        .FileName 
                        .Trim('"'); 
        filename = hostingEnv.WebRootPath + $@"\{filename}"; 
        size += file.Length; 
        using (FileStream fs = System.IO.File.Create(filename)) 
        { 
            file.CopyTo(fs); 
            fs.Flush(); 
        } 
    } 
    return View("UploadFeatures"); 
} 


Regards, 
Prince 



DD Davide D Angelo February 12, 2018 10:01 AM UTC

Hello Prince,
I try your solution, and I'm sorry but no files are passed.

I open your solution with VS 2017 enterprise on localhost, EDGE browser.
Thanks,
Davide


PO Prince Oliver Syncfusion Team February 13, 2018 12:07 PM UTC

Hi Davide,   
  
Thank you for your update.   
  
We suspect that the issue might be due to the Edge browser’s support for <input> element’s “accept” attribute. In our UploadBox control, the input upload element has “accept” attribute to allow only specific file types, which is not supported in Edge browser. Kindly refer to the following link:https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7358734/   
  
In the provided sample, “extensions-allow” property is set as ".pdf" so the accept attribute will be set to “.pdf”. This will not work in Edge browser, so if any other file type is selected instead of PDF, it will not be received by the controller during form post. This could be the cause of your issue. If the selected file is PDF document, then it will be uploaded properly. We have attached a video demonstrating the same. Kindly refer to the following link:    
  
We have reattached the sample for your reference, please find the sample at the following link:http://www.syncfusion.com/downloads/support/forum/135715/ze/UploadCoreDragSample1802646108   
  
Regards,   
Prince   



Loader.
Up arrow icon