![]() This name should be the same as the IFormFile parameter of the Upload method in the controller. In the configuration above the paramName states the name that will be used to transfer the file. You have to be a bit careful when setting this configuration. Show a confirm alert and display the image on the page. The Dropzone library has a unique way to set the configuration. Recall the id attribute of the form element. Now it is time to make some adjustments in the Dropzone configuration. The WebRootPath property returns the path of wwwroot to the folder, and the second parameter, uploads, is then appended correctly with the path. The combined method returns the correct path based on the platform the code is executing. You can hard code the file path, but it may not work on other platforms. Always use the IHostingEnvironment interface to resolve the paths. The _environment variable you see in the above code is the instance of the IHostingEnvironment interface which I have injected into the controller. Using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create)) ![]() Var uploads = Path.Combine(_environment.WebRootPath, "uploads") Here is the complete code which handles the file upload. In the case of an MVC application, we would have used the HttpPostedFileBase class. I have pointed it to the Upload ActionResult in my controller class which accepts a parameter of the type, IFormFile. Here, the action attribute points to the ActionResult which is responsible for handling the file upload. Notice the action and class attributes for the form element. There are a few points to be noted in the above HTML. PM> Install-Package dropzoneĪdd reference of js and CSS files on your page. To install Dropzone you can use the Nuget command. It is super easy and has some powerful configurations. I got the drag and drop to work in just 5 minutes. It supports parallel uploads along with cancellation of the files which are in the upload queue, along with a good looking progress bar to show the progress of the upload. While surfing on Github I found this amazing library to upload the files to the server in a unique way with a lot of configurations. Mostly all web applications out there have some amazing ways to upload a single file or multiple files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |