next-s3-upload icon indicating copy to clipboard operation
next-s3-upload copied to clipboard

Document wrapping the route handler

Open ryanto opened this issue 2 years ago • 4 comments

https://gist.github.com/ryanto/1db2c41465ac3432d9eec18b18257111

ryanto avatar Oct 22 '21 15:10 ryanto

@ryanto Came here to ask about this actually

Happy to do a PR for this. Is there a way to intercept the response? Say to save the image URI to your own database for example (without having to do two round trips to the server)?

I guess we could use middleware but it seems clunky

theonlydaleking avatar Apr 12 '22 02:04 theonlydaleking

Heya @theonlydaleking

I'm not sure I follow, could you provide an example of the problem you're running into and what you'd like to avoid. You can intercept the response, but I'd like to get some more context before I send you down a rabbit hole :)

ryanto avatar Apr 12 '22 14:04 ryanto

Specifically wanted to write the URI to a db for downloading later on.

However after digging through the code, I've realised that the upload occurs client-side so this may be tricky.

currently:

let { url } = await uploadToS3(file) 

I want to be able to get this url server-side so i can write it to the db. But i understand the API route just provides the upload credentials so i guess this isn't possible? / would require another trip to the server

theonlydaleking avatar Apr 13 '22 00:04 theonlydaleking

Yup, exactly. Once you get the url back from uploadToS3 you can send it to your server with an API request. We've been using this pattern for a while and it works great.

ryanto avatar Apr 13 '22 00:04 ryanto