Posting a request with a file produces error: Failed to construct 'URL': Invalid URL
See original GitHub issueVersions:
@inertiajs/inertia
version: ^0.10.1@inertiajs/inertia-react
version: ^0.7.1
Describe the problem:
When posting a request with the useForm
helper that has a file, the browser reports an error as seen here:
index.js:1 Uncaught TypeError: Failed to construct 'URL': Invalid URL
at p (index.js:1)
at e.n.visit (index.js:1)
at e.n.post (index.js:1)
at eval (index.js:1)
at post (index.js:1)
at handleSubmit (Edit.jsx:95)
at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
at invokeGuardedCallback (react-dom.development.js:4056)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070)
When I remove the file, everything posts fine.
Steps to reproduce:
Use the useForm
helper hook to post a request with a file.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Unhandled exception rendering component: Failed to ...
It should be a valid URL in the format: "{AAD B2C INSTANCE}/{TENANT DOMAIN}/{SIGN UP OR SIGN IN POLICY}".
Read more >TypeError: Failed to construct 'URL': Invalid URL - Treehouse
Hello, I'm attempting to use images and videos in my react component and I'm receiving one of two errors. Where I try the...
Read more >How to Fix a 400 Bad Request Error (Causes and Fixes) - Kinsta
The 400 Bad Request error indicates that the server cannot or process the request due to a client error. Read about the common...
Read more >How to Parse URL in JavaScript: hostname, pathname, query ...
How to easily parse URL in JavaScript and access components like hostname ... error; // => TypeError, "Failed to construct URL: Invalid URL"....
Read more >Server error: The URL is invalid. It may refer to a nonexistent ...
Are you using the hostname, ip address or localhost to connect to the site? I would double check that. You could also try...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The issue still exist but I have come up with following solution -
change
post(route('users.update', user.id));
topost(route('users.update', user.id).url());
Closing this, as it appears to be a duplicate of https://github.com/inertiajs/inertia/issues/782
While we still use Ziggy’s route helper in the PingCRM demo app, we intend to replace this with template strings or hardcoded URLs in a future build. In part to work around issues such as these, but also to reduce the initial page render and to make our demo application more straight forward.
Personally, I consider the following to be good alternatives:
or something like