question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Location Header

See original GitHub issue

I’m working in a project that I need to generate a presigned Url for upload and would be nice if was possible to send a custom Location header with client query params. The actual behavior of tusdotnet is call SetReponseHeaders after file creation so is no possible to override the generated Location.

For exemple:

  1. Client send and request to my API endpoint
  2. Then my API with validate the user grants and return a presigned upload url, like that https://localhost/upload?token=12345
  3. Client do a tus upload to the presigned url given from API
  4. My tus server will keep it on Location header, like that Response.Location = $"/upload/{ctx.fileId}?token=12345"
  5. So that when my client can continue the PATCH requests to the Location response with presigned params
  6. Then OnFileCompleteAsync my tus server can have access to client query params and do some insert based on token data

Would be nice to have the concept above, where tus server can keep or customize the final Location header. I’m already using a similar approach that I send the token on a Upload-Token header, but custom Location headers will give more control for server.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
kallebysantoscommented, May 9, 2023

@intobrackets In my point of view you’re probably confusing the Location header witch where the file will be saved to. If you follow the tus protocol specification you will see that is divided in many protocol sections.

Creation workflow

When a client wants to initiate an upload it will perform a HTTP POST request and the server will handle it storing the file metadata and cache stuff. tusdotnet at this point will trigger OnBeforeCreate and OnCreateComplete events and will assign an uuid to after identify the currently upload file.

The resulting Location header specifies where the client should PATCH the file content. So it doesn’t says where will the file be saved.

File processing and storing occurs on SERVER SIDE, clients don’t needs to know about file paths or Disk Storing logic, they only need the Location for the API UPLOAD ENDPOINT

If you want to customize how server will store the uploaded files, you need to overwrite the file resolution mechanism! Looking to Xtensible.TusDotNet.Azure I found create_file_custom_id test example that will overwrite the file Id creation, maybe can be useful for your use case. After scraping deeper on that library I also found GetAppendBlobClient mechanism. My suggestion is that you need to concatenate the file id with some prefix using Xtensible.TusDotNet.Azure API.

Example: <folder_id>/<file_id>. Probably it will broke the tusdotnet API resolution EndpointConventionBuilderExtensions but you can try change the resolver pattern to something like:

app.MapTus("/files/{folder_id?}")

Or do a PR for Xtensible.TusDotNet.Azure implementing some custom container resolution logic, keep in mind that internal file storing resolution should be entire server side in order to not impact tus protocol comunincation.

1reaction
intobracketscommented, May 9, 2023

Thank you @kallebysantos for your reply. I am using Tus (Uppy with Tus on Front + Tusdotnet + Xtensible.TusDotNet.Azure on the Back) to upload files and sotre it into Azule Blob Storage

  • Why i tried to change the location ? => i would like to store every uploaded file to a sub folder on the blob container, because, by default it store files to the root container folder. I hope to have been clear. Thanks in advance.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Location - HTTP - MDN Web Docs - Mozilla
Location is a header associated with the response, while Content-Location is associated with the entity returned. Header type, Response header.
Read more >
Create custom headers in backend services | Load Balancing
Configure custom response headers · Go to the load balancing summary page. · Click Backends. · Click the name of a backend service....
Read more >
Custom HTTP headers : naming conventions
The recommendation is was to start their name with "X-". E.g. X-Forwarded-For , X-Requested-With . This is also mentioned in a.o. section 5 ......
Read more >
Content-Location - HTTP - MDN Web Docs - Mozilla
The Content-Location header indicates an alternate location for the returned data. The principal use is to indicate the URL of a resource ...
Read more >
Custom Headers <customHeaders>
Custom response headers are sent to the client together with the default HTTP header. Unlike redirect response headers, which are returned in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found