next-s3-upload
next-s3-upload copied to clipboard
Document wrapping the route handler
https://gist.github.com/ryanto/1db2c41465ac3432d9eec18b18257111
@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
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 :)
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
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.