kit icon indicating copy to clipboard operation
kit copied to clipboard

Cannot access PUT files outside of formdata.

Open kattschan opened this issue 1 year ago • 1 comments

Describe the bug

I have a PUT function inside of a +server.js file. If a file is uploaded to the server and it is not in a multipart form, there is no way to access the file.

Reproduction

Reproduction can be found here: https://github.com/kattschan/sveltekit-bugreport-repro. Run it on your machine (StackBlitz wouldn't play nice with curl), and try, for instance curl --upload-file package.json http://localhost:5173/package.json and see what gets outputted to console. Using all of the ways to extract data from the response, there is no way to get the file attached in this manner.

Logs

TypeError: Content-Type was not one of "multipart/form-data" or "application/x-www-form-urlencoded".
    at node:internal/deps/undici/undici:4265:19
    at successSteps (node:internal/deps/undici/undici:4288:27)
    at consumeBody (node:internal/deps/undici/undici:4294:9)
    at _Request.formData (node:internal/deps/undici/undici:4242:18)
    at PUT (O:\projects\sharkfiles\src\routes\[filename]\+server.js:9:33)
    at Module.render_endpoint (O:\projects\sharkfiles\node_modules\@sveltejs\kit\src\runtime\server\endpoint.js:43:24)
    at resolve (O:\projects\sharkfiles\node_modules\@sveltejs\kit\src\runtime\server\respond.js:443:23)
    at async Module.respond (O:\projects\sharkfiles\node_modules\@sveltejs\kit\src\runtime\server\respond.js:319:20)
    at async file:///O:/projects/sharkfiles/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:524:22

(when running request.formData())

System Info

O:\projects\sharkfiles>npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"
Need to install the following packages:
[email protected]
Ok to proceed? (y)


  System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-12400F
    Memory: 19.60 GB / 31.86 GB
  Binaries:
    Node: 20.15.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.7.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (126.0.2592.113)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.2.2
    @sveltejs/kit: ^2.0.0 => 2.5.18
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.1
    svelte: ^4.2.7 => 4.2.18
    vite: ^5.0.3 => 5.3.5


O:\projects\sharkfiles>

Severity

serious, but I can work around it

Additional Information

my current workaround is to use an express server with middleware, but this introduces added complexity.

kattschan avatar Jul 26 '24 21:07 kattschan

we need "upload" dir,make kit easier.

ayuancool avatar Aug 04 '24 02:08 ayuancool

Hi kattschan, I couldn't reproduce this issue using the provided reproduction. I'll close this issue for now but feel free to share another minimal reproduction and I'll re-open this issue.

teemingc avatar Oct 28 '24 02:10 teemingc