What is the custom handling method after the file upload / program panic crash of the Golang GinWeb framework
This article mainly explains the "Golang GinWeb framework file upload / program panic crash after the custom processing is what", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "Golang GinWeb framework file upload / program panic crash after the custom processing is what" it!
Upload files
Single file upload
Note: the file name must be safe and reliable. You need to remove the path information and keep the file name.
Package main import ("fmt"github.com/gin-gonic/gin"log"net/http"os") func main () {router: = gin.Default () / / Set a lower memory limit for multipart forms (default is 32 MiB) / / sets the maximum memory limit of the request form. The default is 30MB / / internal call to the ParseMultipartForm method of the http request, which requires passing in a byte To fetch the data of the MultipartForm field First parse the Form using the ParseMultipartForm () method, which reads all the data, but you need to specify the maximum number of bytes to be saved in memory, and the remaining bytes are saved in the temporary disk file maxMultipartMemory: = int64 (8