tus-sender: resolveUploadUrl does not work properly when Location header is relative
See original GitHub issueDescribe the bug
400 bad request response upon uploading when using the official tusdotnet
server library.
To Reproduce Steps to reproduce the behavior:
- Clone https://github.com/tusdotnet/tusdotnet
- Run the
AspNetCore_netcoreapp3.1_TestApp
- Use it as a destination:
http://localhost:5006/files
- Check your browser’s network tab
Expected behavior There woudn’t be a 400 bad request response.
Versions 0.13.4, all browsers
Code
import React from "react";
import TusUploady from "@rpldy/tus-uploady";
import UploadButton from "@rpldy/upload-button";
export const Uploader = () =>
(<TusUploady
destination={{ url: "http://localhost:5006/files" }}
chunkSize={2142880}
featureDetection={true}
>
<UploadButton/>
</TusUploady>)
Solution
I noticed tusdotnet
returns the following Location
header on the first POST request:
/files/75fc454598bb4adca40a831ac62cbd13
The next PATCH request goes to the URL: http://localhost:5006/files/files/75fc454598bb4adca40a831ac62cbd13
– which obviously does not exist.
The issue is caused by resolveUploadUrl
:
https://github.com/rpldy/react-uploady/blob/52e71e9a5785df5c2d3eccd3605df733aa6af683/packages/core/tus-sender/src/tusSender/initTusUpload/createUpload.js#L12
specifically the else
clause:
else {
uploadUrl = [
createUrl.replace(/\/$/, ""),
location.replace(/^\//, "")
].join("/");
}
Maybe the Location
header response can just be appended to the URL, but I don’t know enough about this codebase or the tus ecosystem to verify whether that would work.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
@yoavniran Thanks for the quick fix! Can confirm it’s working. 👍
Hi @yoavniran,
Yes 😉
I’m sorry, this is my mistake. I was debugging multiple versions of tusdotnet and had multiple projects. I’ve updated the description.