Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proposal] Add an option to perform a HEAD request before the upload #31

Open
oliverpool opened this issue Nov 25, 2019 · 0 comments
Open

Comments

@oliverpool
Copy link
Contributor

First of all, thanks for this very cool library!

I have a feature request/ proposal for the following usecase:

I have a custom server implementation, which will give the same upload endpoint, if it believes the files are the same (i.e. the POST /files/ redirects to /files/someHash for every file that matches a specific test - since those file are actually identical).

I can't solve this using the fingerprint system, since the two uploads might be done from two different computers and the fingerprint is computed by the server.

This library works fine if the upload not started before, but it doesn't work if a part of the file has been already uploaded (ErrOffsetMismatch).

I would like to add an option to the config (RequestOffsetOnUploadCreation) to tell the client to getUploadOffset on CreateUpload.

Change would be like:

diff --git a/client.go b/client.go
index b5923d1..1b43b2c 100644
--- a/client.go
+++ b/client.go
@@ -110,7 +110,17 @@ func (c *Client) CreateUpload(u *Upload) (*Uploader, error) {
                        c.Config.Store.Set(u.Fingerprint, url)
                }
 
-               return NewUploader(c, url, u, 0), nil
+               var offset int64
+
+               if c.Config.RequestOffsetOnUploadCreation {
+                       offset, err = c.getUploadOffset(url)
+
+                       if err != nil {
+                               return nil, err
+                       }
+               }
+
+               return NewUploader(c, url, u, offset), nil
        case 412:
                return nil, ErrVersionMismatch
        case 413:

What do you think ?

Can I make a PR with this change ? Do you have an idea for a name, better than RequestOffsetOnUploadCreation ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant