Tus PHP server, file overwrite scenario with Uppy

I’m trying to make a custom php server for tus, based on implementation - examples.
After reading documentation and going through examples, am not shure what is right aprouch for scenario in which file already exists on server and to ask for overwrite.
In first POST request if file is found, what response shuld be (not shure if 409 is ok)?
How to handle it in Uppy in this scenario: modal with user confimation, and to continue upload or reject.

Ideally your tus server generates a unique ID so that there’s never a collision. Otherwise you can corrupt data unintentionally. If you want to intentionally override a file, you should have some server hooks (like onUploadFinish for tus Node.js or post-finish for tus Go) to do this yourself.

Well actualy I dont want to generate another ID, because i dont want upload to happen at all unless I want it to (user confirms in the modal).

If you want to reject an upload because a similar resource already exists, I would return a 400 response with a body describing the failure. In Uppy, you would then have to catch that error and respond to it in an application-specific way (e.g. ask the user for input). I don’t think Uppy offers a ready-to-use component for this.

There is whole discusion here about response code:
rest - HTTP response code for POST when resource already exists - Stack Overflow)
and log story short - 409 Conflict is the most appropriate

So the scenario would be:
server returns 409
uppy throws out the modal, I confirm, I send a flag in the request to ignore that the resource exists and repeat the upload

A 409 is also fine, the choice of the response code depends on individual preferences and the design of the API. You should just double check that a 409 is not returned for PATCH requests because this combination has a special meaning in tus, indicating that the client-supplied Upload-Offset does not match the server’s expectation. But for POST request you should be able to return 409.

Ok, thanks…
I haven’t had time to implement all of this yet, but when I do, I’ll report the results

1 Like