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

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

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

Loading…
Cancel
Save