Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tus-sender: resolveUploadUrl does not work properly when using relative path #246

Closed
TheMadKow opened this issue Oct 4, 2021 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@TheMadKow
Copy link

TheMadKow commented Oct 4, 2021

Describe the bug
While using relative path, first connection with server succeeds, and then fails.

When using url : '/relative-path/files' the client will fail due to the following error

tusSender.create: create upload failed TypeError: Failed to construct 'URL': Invalid URL
at resolveUploadUrl (createUpload.js:12)
at handleSuccessfulCreateResponse (createUpload.js:24)
at createUpload.js:79

following code lines:

    //absolute location, concatenate to upload URL without any other path
    uploadUrl = new URL(createUrl).origin.replace(/\/$/, "") + location;

because createUrl variable is relative, and URL function throws an error.

To Reproduce
It's in my code base, maybe the same as issue #242 but with relative path instead of absolute path.
That is -- Use it as a destination: "/files"

Expected behavior
To be able to provide relative path to the server.

Versions
After release 0.13.5 on Chrome/Edge Chromium.

Code

** Doesn't Work with relative URL **

        <TusUploady
            destination={{
                url: '/Core/HandleTusFiles',
....

</TusUploady>

** Works with absolute URL **

        <TusUploady
            destination={{
                url: 'https://localhost:44315/Core/HandleTusFiles',
....

</TusUploady>
@yoavniran
Copy link
Collaborator

thanks @TheMadKow its very clear now what the issue is.
I will issue a fix for this very soon

@yoavniran yoavniran self-assigned this Oct 4, 2021
@yoavniran yoavniran added the bug Something isn't working label Oct 4, 2021
@TheMadKow
Copy link
Author

Thanks @yoavniran :)
Do let me know if more information is needed ^^

@yoavniran
Copy link
Collaborator

@TheMadKow Just making sure, since you provide a destination without the origin and you want to return an absolute path from your TUS server. This means that the final upload URL will be just the absolute path.

Example:

If: Destination URL == /Core/HandleTusFiles
and: Location header == /files

Upload URL will be: /files

This is your expectation, correct?

@TheMadKow
Copy link
Author

TheMadKow commented Oct 6, 2021

@yoavniran - the issue is the exception thrown by the code after initial handshake is establised.

If: Destination URL == /Core/HandleTusFiles
and: Location header == https://localhost:44315/Core/HandleTusFiles

Upload URL will be: https://localhost:44315/Core/HandleTusFiles/[guid]


Currently, the destination URL is relative (/Core/HandleTusFiles), and Location header returns a correct absolute path (location: /Core/HandleTusFiles/dade9da9f5f141b7aa4a8f49cd18ba6b), but afterwards it fails.

That is, the first post request works just fine, and returns correct location with status code 201.
The following requests fails due to the following error

tusSender.create: create upload failed TypeError: Failed to construct 'URL': Invalid URL
    at resolveUploadUrl (createUpload.js:12)
    at handleSuccessfulCreateResponse (createUpload.js:24)
    at createUpload.js:79

Specifically, I think the URL function tries to work with the relative path, and not the provided location from the server.

If that's not possible, maybe it's easier to specify that the destination URL should always be absolute.
Because when I do write the absolute path, it works just fine :)

Best,
Eliran :)

@yoavniran
Copy link
Collaborator

The problem is clear and I have a fix for it - #247
I just wanted to make sure the fix is what you need. I believe it is. I will merge later on today and release a new version

@TheMadKow
Copy link
Author

Thank you ! :)

@yoavniran
Copy link
Collaborator

0.13.6 is now out. Please check that it does solve the problem.
thanks!

@TheMadKow
Copy link
Author

Yes, I can confirm it works fine now.
Thank you for the quick fix !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants