Skip to content

Commit

Permalink
Read file to be uploaded fully into memory to have Content-Length hea…
Browse files Browse the repository at this point in the history
…der set
  • Loading branch information
wilriker committed Aug 12, 2019
1 parent be0bdbc commit 4b673d4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions commands/upload.go
Expand Up @@ -7,6 +7,9 @@ import (
"path/filepath"
"strings"

"bytes"
"io/ioutil"

"github.com/wilriker/rfm"
)

Expand Down Expand Up @@ -107,15 +110,14 @@ func (u *upload) Upload(localPath, remotePath string) error {
}
rp := rfm.CleanRemotePath(fmt.Sprintf("%s/%s", remotePath, lp))

f, err := os.Open(path)
fileContent, err := ioutil.ReadFile(path)
if err != nil {
return err
}
defer f.Close()
if u.o.verbose {
log.Printf("Uploading %s to %s", path, rp)
}
_, err = u.o.Rfm.Upload(rp, f)
_, err = u.o.Rfm.Upload(rp, bytes.NewReader(fileContent))
return err
})
}

0 comments on commit 4b673d4

Please sign in to comment.