How to upload large images and large files on website

Lionsure 2020-08-21 Original by the website

The website can only upload 4MB images or files by default. If the uploaded file is larger than 4MB, the upload will fail. Generally speaking, uploading large images or large files adopts the method of splitting, that is, a large file is divided into many small pieces, and one piece is uploaded each time, so that it will not exceed 4MB. Uploading in this way is a bit more troublesome. You need to divide the file into small pieces before uploading, and then combine these pieces into one file after receiving; but there is also an advantage, upload a little and save a little. When the network is unstable, it is suddenly disconnected, and the uploaded part is still there; If you upload it all at once, you have to upload it again after the network is disconnected, because the entire file will only be saved after uploading it.

Nevertheless, the network is now faster than before. Uploading a few megabytes of files will be completed in one shot. The possibility of network disconnection is very small. Even if it is suddenly disconnected, uploading again is fast. So there is no need to use splitting methods for images or files larger than 4MB. Can we break through the 4MB limit and upload all at once? In fact, the website development environment and server do not have a hard limit to upload only 4MB, but can only upload files up to 4MB by default. If you want to upload images or files larger than 4MB, just add the number of megabytes of images or files allowed to be uploaded on a certain page in the configuration file, and you can upload files of the set size. The reason for the limitation of uploading files of 4MB is for the safety of network, to prevent people with ulterior motives from uploading virus files to the server to damage the website or server.

 

How to upload large image files and large files on website?

Take the .net website as an example, if you want to upload a large image or file larger than 4MB on a webpage, you only need to add the maximum number of files allowed to be uploaded in the website configuration file Web.config. The specific code is as follows:

<configuration>
              <location path="upload/upimage.aspx">
                     <system.web>
                            <httpRuntime maxRequestLength="20480" executionTimeout="600"/>
                     </system.web>
              </location>
       </configuration>

The above code allows the upimage.aspx file in the upload folder to upload large images or files with a maximum size of 20MB. The upload limit time is 600 seconds, that is, if the upload is not completed within 10 minutes, the server will terminate the upload, so be sure to set enough time.