Skip to content

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

@oliverpool

Description

@oliverpool

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions