Upload image/file and save it to filesystem no longer works same way, what is method to do this now? #7974
-
I wrote about this issue here #7924 where a previous upload method no longer works. @Conduitry recommended writing here and Discord. Already created a topic in Discord. This repo https://github.com/Programonaut-Blog/sveltekit-image-upload is fine for updating an image in filesystem using a previous version of Sveltekit: Something changed in Sveltekit, and a very common use case "write a file to filesystem" has what seems like no documentation for Sveltekit in its current form. What's the recommended way to do this now? I would like the application to have the ability to upload an image and save on filesystem. This worked fine before, but all the examples online are using old Sveltekit and error out. This explains using request.json() that I am used to https://stackoverflow.com/questions/70990443/unable-to-access-request-body-from-the-endpoint-js-in-sveltekit-skeleton-project, but I get an error with "Unexpected token o in JSON at position 1" ReproductionUse this same code with latest version of Sveltekit, no longer works. LogsWhen attempting to use .json() with code above I get this Unexpected token o in JSON at position 1
SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>) System InfoMac, svelte latest 1.0.0-next.571 Severityserious, but I can work around it Additional InformationStill boggled Sveltekit doesn't have core common use cases which would be updated with major changes, would help with adoption and probably cut down on defects. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
I've created an updated example you can find here: https://github.com/s3812497/svelte-kit-upload-image Please see the following documents for any other migrations you may require: |
Beta Was this translation helpful? Give feedback.
-
Why can't we provide an out of the box 'upload' directory? |
Beta Was this translation helpful? Give feedback.
I've created an updated example you can find here: https://github.com/s3812497/svelte-kit-upload-image
The most notable change to get it working was migrating the old file-based routing to the new folder-based routing system.
Please see the following documents for any other migrations you may require: