Skip to content

Commit

Permalink
Pass io.ReadSeeker to tus client instead of io.Reader
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Oct 21, 2020
1 parent 970c59c commit c28cf60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ type transferClaims struct {
}

func (s *svc) sign(_ context.Context, target string) (string, error) {
ttl := time.Duration(s.c.TransferExpires) * time.Second
// Tus sends a separate request to the datagateway service for every chunk.
// For large files, this can take a long time, so we extend the expiration
// for 10 minutes. TODO: Make this configurable.
ttl := time.Duration(s.c.TransferExpires) * 10 * time.Minute
claims := transferClaims{
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(ttl).Unix(),
Expand Down
16 changes: 14 additions & 2 deletions internal/http/services/owncloud/ocdav/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package ocdav
import (
"io"
"net/http"
"os"
"path"
"regexp"
"strconv"
Expand Down Expand Up @@ -166,11 +167,22 @@ func (s *svc) handlePut(w http.ResponseWriter, r *http.Request, ns string) {
return
}
}
fileName, fd, err := s.createChunkTempFile()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
defer os.RemoveAll(fileName)
defer fd.Close()
if _, err := io.Copy(fd, r.Body); err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}

s.handlePutHelper(w, r, r.Body, fn, length)
s.handlePutHelper(w, r, fd, fn, length)
}

func (s *svc) handlePutHelper(w http.ResponseWriter, r *http.Request, content io.Reader, fn string, length int64) {
func (s *svc) handlePutHelper(w http.ResponseWriter, r *http.Request, content io.ReadSeeker, fn string, length int64) {
ctx := r.Context()
log := appctx.GetLogger(ctx)

Expand Down
7 changes: 6 additions & 1 deletion pkg/storage/utils/eosfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ func (upload *fileUpload) GetInfo(ctx context.Context) (tusd.FileInfo, error) {

// GetReader returns an io.Reader for the upload
func (upload *fileUpload) GetReader(ctx context.Context) (io.Reader, error) {
return os.Open(upload.binPath)
f, err := os.Open(upload.binPath)
if err != nil {
return nil, err
}
defer f.Close()
return f, nil
}

// WriteChunk writes the stream from the reader to the given offset of the upload
Expand Down

0 comments on commit c28cf60

Please sign in to comment.