tus / tus-js-client

A pure JavaScript client for the tus resumable upload protocol
https://tus.io/
MIT License
2.12k stars 316 forks source link

Is it possible to remove fingerprint in any error except network interruptions? #704

Closed ADTC closed 2 months ago

ADTC commented 3 months ago

Is your feature request related to a problem? Please describe. We want to minimize frustrations for user, by simply removing the fingerprint in the local storage on any and all errors with the exception of network loss. This is the only time we want to keep the fingerprint, so that when the network is restored, the user may try uploading the file again and resume the upload. In all other cases, we want the user to begin a new upload.

Describe the solution you'd like

Describe alternatives you've considered

Can you provide help with implementing this feature? The tus team is always happy to improve your situation but our time is also sadly limited, so it may take some time until we can work on your request. If you have the resources and knowledge to take a shot at your idea, we are more than eager to assist you.

Yes, I can try if there's a basic idea spelt out.

Additional context Add any other context or screenshots about the feature request here.

We already have removeFingerprintOnSuccess: true to allow same file to be uploaded multiple times.

Acconut commented 3 months ago

removing the fingerprint in the local storage on any and all errors with the exception of network loss.

You might also want to consider not deleting fingerprints for server errors (i.e. 5xx). They can happen and the client can try to resume in those cases.

* Using `onError` or `onShouldRetry` callbacks, but I'm not sure how to remove fingerprint or how to know whether an error is network interruption.

If err.originalResponse is set, the error was raised in response to a failed request. Either because the response was malformed or not received at all. So, you could do a check like this:

// 0 should mean no response received. But I didn't test this
const isNetworkLossError = err.originalResponse !== null && err.originalResponse.statusCode === 0

You can then use tus.defaultOptions.urlStorage.removeUpload to delete the entries corresponding to your upload: https://github.com/tus/tus-js-client/blob/main/docs/api.md#urlstorage

I hope these pointers help you!

Acconut commented 2 months ago

Closing this issue due to inactivity. Feel free to leave a comment if you want to continue the discussion :)