sveltejs / examples

A collection of Svelte(Kit) examples
MIT License
35 stars 5 forks source link

SvelteKit file uploads #8

Closed karimfromjordan closed 1 year ago

karimfromjordan commented 1 year ago

The previous two PRs #6 and #7 were deleted because I merged the two branches and cleaned up a few things. So this branch contains two projects — one for plain Node.js and for S3. It covers what was discussed in the file uploads issue #2

Unfortunately, POST requests with SvelteKit do not work in Stackblitz so the only way to test these examples is to clone them. The CSS is very basic and mostly handles layout for now. Functionality-wise it probably does everything you would from such an example. The only thing that is kinda missing is a place where possible errors get displayed although the only error that can really happen is that a file with the same name is uploaded again, in which case currently the request is rejected in the Node.js example and nothing happens.

dummdidumm commented 1 year ago

one thing i noticed is that requires node 18 because of the fromweb method. is there a way around that? if no or not easy we should at least note this in the readme

karimfromjordan commented 1 year ago

one thing i noticed is that requires node 18 because of the fromweb method. is there a way around that? if no or not easy we should at least note this in the readme

Yes, true I should have added that to the README. It works with Node.js >=17.0.0. There is a manual way to deal with this but it's supposed to be more complex and I haven't found a good explanation for that.

Edit: I saw I actually already added it to the README at the bottom but will move it up to the top.

karimfromjordan commented 1 year ago

One thing I haven't done yet (feel free to do it if necessary) is split the examples into svelte and sveltekit sub directories.

dummdidumm commented 1 year ago

yeah let's do that in a follow-up PR. To not have too much nesting, we should probably do that at the top level

karimfromjordan commented 1 year ago

Ok, I just made a few last minor improvements but I'm done now.

dummdidumm commented 1 year ago

Nice! One last question: Do we need the S3-variables to be part of the dynamic env imports or can it be imported from the static ones, too?

karimfromjordan commented 1 year ago

Good question. I would say they should be dynamic. There is one public static env var used on the page and the ones used on the backend are dynamic. My idea was that when you build the project and deploy it to a container you can inject the env vars at runtime with systemd, Docker etc. These variables are also sensible. The env var used on the page is imported from static.

karimfromjordan commented 1 year ago

Should I create a PR where we move the folders — into a svelte and sveltekit directory at the top level? The sveltekit- prefix of the file upload examples can then be stripped. Would the counters example be a svelte or sveltekit example?

dummdidumm commented 1 year ago

Let's take this discussion to Discord so other maintainers can chime in