Propery determine the http-upload max-file-size.

http_upload
Martin Dosch 5 years ago
parent 0d6d4a5479
commit 9702df6c84

@ -90,8 +90,9 @@ func httpUpload(client *xmpp.Client, jserver string, filePath string) string {
var iqDiscoItemsXML IQDiscoItemsType var iqDiscoItemsXML IQDiscoItemsType
var iqDiscoInfoXML IQDiscoInfoType var iqDiscoInfoXML IQDiscoInfoType
var uploadComponent string
var iqHttpUploadSlotXML IQHttpUploadSlot var iqHttpUploadSlotXML IQHttpUploadSlot
var uploadComponent string
var maxFileSize int64
// Get file size // Get file size
fileInfo, err := os.Stat(filePath) fileInfo, err := os.Stat(filePath)
@ -158,18 +159,28 @@ func httpUpload(client *xmpp.Client, jserver string, filePath string) string {
} }
} }
if uploadComponent == "" { if uploadComponent == "" {
log.Fatal("No http upload component found.") log.Fatal("No http upload component found.")
} }
maxFileSize, err := strconv.ParseInt(iqDiscoInfoXML.X[1].Field[1].Value, 10, 64) for _, r := range iqDiscoInfoXML.X {
if err != nil { for _, t := range r.Field {
log.Fatal("Error while checking server maximum http upload file size.") if t.Var == "max-file-size" {
maxFileSize, err = strconv.ParseInt(t.Value, 10, 64)
if err != nil {
log.Fatal("Error while checking server maximum http upload file size.")
}
}
}
} }
if fileSize > maxFileSize { // Check if the file size doesn't exceed the maximum file size of the http upload
log.Fatal("File size " + strconv.FormatInt(fileSize/1024/1024, 10) + // component if a maximum file size is reported, if not just continue and hope for
" MB is larger than the maximum file size allowed (" + // the best.
strconv.FormatInt(maxFileSize/1024/1024, 10) + " MB).") if maxFileSize != 0 {
if fileSize > maxFileSize {
log.Fatal("File size " + strconv.FormatInt(fileSize/1024/1024, 10) +
" MB is larger than the maximum file size allowed (" +
strconv.FormatInt(maxFileSize/1024/1024, 10) + " MB).")
}
} }
// Request http upload slot // Request http upload slot

Loading…
Cancel
Save