This is a created article in which the information may have evolved or changed.
Now there is a demand, the server needs to upload the file to parse, for the zip that does not contain the specified folder, need to Error! If the code is compliant, save it.
Simply put, how to analyze the file structure without saving the uploaded zip file
Func (P *filestruct) validfile () error {
ContentType: = P.file.header.get ("Content-type")
If contentType! = "Application/zip" {
Return to FMT. Errorf ("Please upload zip resource bundle")
}
There is a problem with the following line, because only the name of the file is obtained, the file is not read, this is the main problem
R, Err: = Zip. Openreader (P.file.filename)
If err! = Nil {
Return to FMT. Errorf ("Error")
}
If!container (R, "3123123") {//The reader analysis structure obtained by
Return to FMT. Errorf ("Make sure there are 3123123 folders")
}
return Nil
}
254 Reads