It is my first time using AWS S3. I am trying to store images (jpg/png etc.) on S3 and have the URL stored on a database. The application essentially logs the user's session and S3's URL when they submit a picture (profile picture), and when they want to update the profile picture, the original S3 stored picture will be deleted and replaced with a new one.
Currently I am using https://next-s3-upload.codingvalue.com/setup next-s3-upload, which successfully uploads images onto S3 but not deleting. The entire tech stack is NextJS, Prisma and Planetscale, to be hosted on Vercel.
Any tips on how to operating CRUD for S3 would be appreciated, as I am stuck on reading up AWS-SDK but no joy on React/NextJS.
Read the AWS SDK for JavaScript Developer Guide. This will teach you how to perform AWS operations using the AWS SDK for JavaScript, including many Amazon S3 operations.
What's the AWS SDK for JavaScript?
This SDK can be used with React too.
Getting started in React Native
For Amazon S3 operations, see:
Amazon S3 examples using SDK for JavaScript V3
To delete an object, see this topic that shows you the code example:
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/javascript_s3_code_examples.html#w4aac23b9c25c13
You can also find Amazon S3 code examples in Github here:
https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javascriptv3/example_code/s3/src
Related
new to Gatsby here.
I've followed the Gatsby-image guide and store my photos in an images folder in my project and pull the photos via graphQL from there. It works great locally but I guess that kind of storage is not meant for actually production? As I get the 'failed to load resource error' from the public HTML and blurry images when deployed. From browsing through stack overflow and github it looks like a ton of people run in to this.
So where does everyone store their photos? Just curious for some advice, thanks!
You have plenty of choices:
Cloud-Based solutions
AWS S3 (S3, S3 Glacier etc...)
Google Cloud Storage
Azure Blob Storage
Others:
Node framework's public folder. (Most of the time it's statically served)
Directly serve them from an Nginx or an Apache.
The list isn't exhaustive.
I recommend you to use Cloud storage because it's cheaper and you have 99.99% availability. It is also easier to link them with cloud services like permission ones (IAM of AWS for example).
And for your use case AppSync for GraphQl.
I have some questions regarding deploy a React Application on cloud front.
How the caching and updating of front end website hosted on Cloud Front works?
When I upload a new files to the bucket I will see the changes IMEDIATELY after accessing the site again? If not, how long it will take?
I need to make an invalidate request to see the changes working on the website? If yes, how long it will take?
What is the best approach to deal with cache and update of Single Page applications in Cloud Front? (I am using a React Application and Webpack)
What you need to do is purge the cache of the bucket or "invalidating" a file.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html
So install the aws cli and run the following command:
aws cloudfront create-invalidation --distribution-id $CDN_DISTRIBUTION_ID --paths "/*"
I'd suggest you use your S3 bucket for development.
I will developing an app in ionic framework, and i use AWS S3 to store picture and documentation , what is the best used databases Amazon DynamoDB or mongodb ? and what the best way to connect AWS S3 with databases ?
finally i want app working in offline and online .
You can use AWS Mobile Hub to serve as your project in AWS. You can use this service to create User Files which does exactly what you are describing for the users and provides tutorials on how to accomplish this.
I would download the AWS Mobile CLI and follow the steps to create your Mobile Hub Project from within your Ionic project root folder.
From there you can then start adding backend features to your app such as S3 for user files, pictures etc..
I would then head over to AWS Amplify and go through their set up tutorial for the Ionic frame work and then you can use Amplifies very easy to use functions right in your components to get and set data.
I just finished a mobile app with these and I can say it was a very easy process once going through the documentation.
I've been able to get jQuery-File-Upload from https://github.com/blueimp/jQuery-File-Upload (python version) to allow my website users to upload images to a google app engine app, however it saves the images (for a limited time) as a blob.
It would be preferable to have the images saved in a google bucket but I'm unable to figure out how to get the files to save in a bucket rather than a blob.
Can anyone recommend a similar way for my website visitors to upload images to my google bucket, or if jQuery-File-Upload to do so?
I created an Appengine Python signed url example here:
There is a cloud API to directly upload files to google cloud bucket via javascript, however implementing security could make things a bit sticky.
In general,It should be fairly easy to use google cloud services found here
use storage insert api call
Now if you like to give access to clients to upload data on you application's behalf, then you may have to build a signed url ,signed with your key and then directly upload to cloud, read more here
I find it easy to do server side operations if the upload size is fairly small by using BlobStore API. You can use the Blobstore API to store blobs in Cloud Storage instead of storing them in Blobstore. Read all about it here.
This method might be the easiest to implement in your case .
Our app directory upload images to S3 from client side and on success we store the url to custom object in salesforce. However I saw a lot of people are indirectly upload images to S3 through salesforce using AWS API. I wonder if my approach pass through the salesforce security review.
1. Its about Salesforce Limits.
If you upload files to AWS via Salesforce, you will not be able to upload files more than 5MB as salesforce can accept files upto 5MB only. By directly uploading to AWS S3, you dont need to worry about this limit anymore.
2. Its Easy.
Uploading files to AWS is very easy science Amazon provides required APIs to do it. You must be knowing difficulties of working in Salesforce Environment while doing this.
3. Its More Secure
S3 provides all possible kind of security features possible. Directing files from Salesforce will make process slow and less secure.