Dawood Abbas

Dawood Abbas

  • NA
  • 32
  • 3.1k

500 (Internal Server Error) while uploading the more than 7MB image

May 29 2021 4:33 PM
How to prevent from 500 (Internal Server Error) while uploading the more than 7MB image in Base64 string
 
I am trying to upload more than 7mb sized image which throwing before hit the server side action method '500 Internal Server Error' where below 7mb images are easily get uploaded.
below I am Serializing the file in angular to Base64 string.
  1. $scope.UploadSysFiles = function (event){  
  2. var file = event.target.files;  
  3. var reader = new FileReader();  
  4. reader.readAsDataURL(file[0]);  
  5. reader.onload = () => {  
  6. $scope.SysFileByteCode = reader.result;  
  7. };  
  8. $scope.SysFiles = file[0];  
  9. }  
and storing all values in one object for sending to server side class object as below
  1. $scope.SystemAccesories[rowIndex] = {};  
  2. $scope.SystemAccesories[rowIndex].ManualFile = $scope.SysFileByteCode;  
  3. $scope.SystemAccesories[rowIndex].FileName = $scope.SysFiles.name;  
  4. $scope.SystemAccesories[rowIndex].FileSize = $scope.SysFiles.size;  
  5. $scope.SystemAccesories[rowIndex].ContentType = $scope.SysFiles.type;  
  6. $scope.SystemAccesories[rowIndex].IsManualFileAvailable = true;  
  7. now sending to server side like below  
  8. $http({  
  9. method: 'POST',  
  10. url: 'http://localhost:*****/Accesories/UpdateAccesories',  
  11. data: { objSystemAccesories: $scope.SystemAccesories},  
  12. headers: { 'content-type''application/json' }  
  13. }).then(function (response) {  
  14. //after get success, further steps  
  15. }  
  16. });  
at backend I created one object class file and getting values in action method like below
  1. public class SystemAccessories  
  2. {  
  3. public string ManualFile { getset; }  
  4. public string FileName { getset; }  
  5. public string FileSize { getset; }  
  6. public string ContentType { getset; }  
  7. public Nullable<bool> IsManualFileAvailable{ getset; }  
  8. }  
  9. [HttpPost]  
  10. public ActionResult UpdateAccesories(SystemAccesories objSystemAccesories)  
  11. {  
  12. //deserialize to byte array annd upload code  
  13. }  
I have updated the `web.config` file by below code
  1. <system.web>  
  2. <httpRuntime targetFramework="4.6.1" maxRequestLength="2147483647" executionTimeout="3600" requestLengthDiskThreshold="2147483647"/>  
  3. </system.web>  
  4. <system.webServer>  
  5. <security>  
  6. <requestFiltering>  
  7. <requestLimits maxAllowedContentLength="2147483647"></requestLimits>  
  8. </requestFiltering>  
  9. </security>  
  10. </system.webServer>  
  11. <system.web.extensions>  
  12. <scripting>  
  13. <webServices>  
  14. <jsonSerialization maxJsonLength="50000000"/>  
  15. </webServices>  
  16. </scripting>  
  17. </system.web.extensions>  
but still getting same issue, no change

Answers (4)