diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..359de09 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Max Pavlov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index d5b8461..0ec94c8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://stand-with-ukraine.pp.ua) + # **jQuery-File-Upload.MVC3** # This is an example of how to integrate a [jQuery-File-Upload plugin](https://github.com/blueimp/jQuery-File-Upload) into an ASP.NET MVC 3 application. @@ -8,4 +10,4 @@ Currently MVC Actions are not used to handle upload/download/delete in the demo, This given, a HttpHandler implmentation is introduced. (thanks go to [Iain Ballard](https://github.com/i-e-b/) and his [ASP.NET handler-based demo](https://github.com/i-e-b/jQueryFileUpload.Net)) -main.js is initialized with large-files in mind, and a thumbnails are smart enough to disaplay everything correctly, so go ahead, take a look and fork if you wish. \ No newline at end of file +main.js is initialized with large-files in mind, and a thumbnails are smart enough to disaplay everything correctly, so go ahead, take a look and fork if you wish. diff --git a/jQuery-File-Upload.MVC3/Controllers/HomeController.cs b/jQuery-File-Upload.MVC3/Controllers/HomeController.cs index 463d058..384917d 100644 --- a/jQuery-File-Upload.MVC3/Controllers/HomeController.cs +++ b/jQuery-File-Upload.MVC3/Controllers/HomeController.cs @@ -91,24 +91,15 @@ private string EncodeFile(string fileName) private void UploadPartialFile(string fileName, HttpRequestBase request, List statuses) { if (request.Files.Count != 1) throw new HttpRequestValidationException("Attempt to upload chunked file containing more than one fragment per request"); - var file = request.Files[0]; - var inputStream = file.InputStream; + var file = request.Files[0]; var fullName = Path.Combine(StorageRoot, Path.GetFileName(fileName)); using (var fs = new FileStream(fullName, FileMode.Append, FileAccess.Write)) { - var buffer = new byte[1024]; - - var l = inputStream.Read(buffer, 0, 1024); - while (l > 0) - { - fs.Write(buffer, 0, l); - l = inputStream.Read(buffer, 0, 1024); - } - fs.Flush(); - fs.Close(); + file.InputStream.CopyTo(fs); } + statuses.Add(new ViewDataUploadFilesResult() { name = fileName, diff --git a/jQuery-File-Upload.MVC3/Upload/UploadHandler.ashx.cs b/jQuery-File-Upload.MVC3/Upload/UploadHandler.ashx.cs index 4d45757..638adcc 100644 --- a/jQuery-File-Upload.MVC3/Upload/UploadHandler.ashx.cs +++ b/jQuery-File-Upload.MVC3/Upload/UploadHandler.ashx.cs @@ -108,16 +108,7 @@ private void UploadPartialFile(string fileName, HttpContext context, List 0) - { - fs.Write(buffer, 0, l); - l = inputStream.Read(buffer, 0, 1024); - } - fs.Flush(); - fs.Close(); + inputStream.CopyTo(fs); } statuses.Add(new FilesStatus(new FileInfo(fullName))); } @@ -194,4 +185,4 @@ private void ListCurrentFiles(HttpContext context) } } -} \ No newline at end of file +}