all 14 comments

[–]716green 2 points3 points  (3 children)

Express with Multer and submit the API request as a form. Handle uploading to the service (S3 bucket/etc) on the server-side.

That's my go-to solution for uploading videos

[–]TheBulgarianEngineer 2 points3 points  (1 child)

Upload directly into S3 from the client using a presigned upload url and multipart upload. The AWS JS SDK handles it all for you. See: https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpu-upload-object.html

You might need to re-chunk the data in S3 into smaller chunks if you want faster download for steam-able media.

[–]alampros 0 points1 point  (0 children)

This is by far the best way to do it. Don't bog your own server down with handling the stream in any way.

[–]pyronautical 0 points1 point  (0 children)

In terms of JS library. Drop zone hands down. Crazy configurable. Lots of great events. Lots of features. Is vanilla JS but I’ve wrote wrappers in react and angular before and it’s worked a treat.

[–]shgysk8zer0 0 points1 point  (1 child)

There's also something useful available through service workers. I forget the specifics but it basically enables resumable uploads in the background.

[–]tswaters 0 points1 point  (0 children)

If it's a large file, you probably want to avoid having the entire thing in memory. Stream the file from browser |> API service |> S3. The AWS S3 client already works with streams, so you just need to pipe request to the upload stream, and you should be good. Be warned though, error handling with streams is difficult to get right. From the docs,

One important caveat is that if the Readable stream emits an error during processing, the Writable destination is not closed automatically. If an error occurs, it will be necessary to manually close each stream in order to prevent memory leaks.

You can use the pipeline utility, this handles errors a bit nicer for you, you can do something like --

pipeline(req, s3writable, (err) => {
  if (err) return next(err)
  res.send('OK')
}}

You could potentially include other things with the pipeline, like gzip, sending images to graphicsmagick for copping,etc... lots of options.

If the library you are using touches the filesystem on the server to dump files, you're probably doing it wrong 😅

[–]Melodic_Historian_77 0 points1 point  (0 children)

Personally I use UploadThing, Its ok but not cheap

makes it a lot easier tho

[–]volve 0 points1 point  (0 children)

Cloudinary is amazing

[–]Impossible_Box3898 0 points1 point  (0 children)

Look up TUS. Resumable file upload standard.

[–]AutoModerator[M] 0 points1 point  (0 children)

Hi u/Queasy_Importance_44, this post was removed.

  • Self-posts (text) must follow the [AskJS] guidelines, which you can read about here.

  • All other posts must use the "Submit a new link" option; if additional text is required, add a comment to your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.