I am trying to design a system where I upload images to a bucket or CDN, .... from a flutter app.
I am wondering if the double upload can be avoided, the one that sends the images to my backend (Node.js API), and the upload that'll send the images to the bucket.
Are there any flaws to only upload once, upload files to a bhucket and then send urls of the files to the backend ?
Thank you
Generating a presigned URL to let the client upload a specific file to S3 is a common pattern. It's important that you don't allow everyone to write to the bucket though.
Check out the documentation on Uploading Objects with Presigned URLs for more details.
In a nutshell: Make sure that the backend generates a presigned URL that doesn't conflict with other objects (lest they be overwritten) and a reasonable time to live. Be aware that the time to live is also limited by the lifetime of the credentials that generate the presigned URL. This means if the temporary credentials of a role are valid for 3 hours and you try to generate a presigned URL that expires after 6 hours it won't fail, but the URL will stop working after 3 hours.