From 3cb405d3a357debecfff0753218082dbae0a37cf Mon Sep 17 00:00:00 2001 From: njfsilva Date: Tue, 4 Feb 2014 15:41:46 +0000 Subject: [PATCH 1/5] Removed Unecessary write to buffer Removed unnecessary write to the buffer since it sometimes causes out of memory exceptions and you can write the inputStream directly to the file. --- .../Controllers/HomeController.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/jQuery-File-Upload.MVC3/Controllers/HomeController.cs b/jQuery-File-Upload.MVC3/Controllers/HomeController.cs index 463d058..f41ef1f 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(files); } + statuses.Add(new ViewDataUploadFilesResult() { name = fileName, From 0e51c08dc4e6fa6aecba2787fa0a766a3dcb02b1 Mon Sep 17 00:00:00 2001 From: njfsilva Date: Tue, 4 Feb 2014 15:44:24 +0000 Subject: [PATCH 2/5] Changed fileStream name since it was wrong --- jQuery-File-Upload.MVC3/Controllers/HomeController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jQuery-File-Upload.MVC3/Controllers/HomeController.cs b/jQuery-File-Upload.MVC3/Controllers/HomeController.cs index f41ef1f..384917d 100644 --- a/jQuery-File-Upload.MVC3/Controllers/HomeController.cs +++ b/jQuery-File-Upload.MVC3/Controllers/HomeController.cs @@ -97,7 +97,7 @@ private void UploadPartialFile(string fileName, HttpRequestBase request, List Date: Tue, 4 Feb 2014 15:46:25 +0000 Subject: [PATCH 3/5] Removed buffer use Sometimes it causes outOfMemoryException and there's no need to write to a separate buffer since you can copy the inputStream directly to the file. --- .../Upload/UploadHandler.ashx.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) 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 +} From 70b29f272617978d35a9851da93204ff580d63cc Mon Sep 17 00:00:00 2001 From: Max Pavlov Date: Wed, 8 Jan 2020 08:26:59 +0200 Subject: [PATCH 4/5] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE 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. From c3eac381b87e3a32b581753fdf1aae3765f174fd Mon Sep 17 00:00:00 2001 From: Max Pavlov Date: Thu, 22 Dec 2022 17:11:06 +0200 Subject: [PATCH 5/5] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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.