All Projects → dabit3 → react-amplify-appsync-files-s3

dabit3 / react-amplify-appsync-files-s3

Licence: other
An example project showing how to upload and download public and private images in GraphQL using AppSync and S3

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to react-amplify-appsync-files-s3

voterocket-lab
AWS Summit Dev Labs: Build a modern serverless web application in minutes using the AWS Amplify Framework
Stars: ✭ 23 (-66.67%)
Mutual labels:  amplify, appsync
aws-appsync-iot-core-realtime-dashboard
This sample application demonstrates a React based web dashboard receiving real-time updates from IoT sensors. The solution is built with AWS AppSync, AWS Amplify, Amazon Location Service, and AWS IoT Core technologies.
Stars: ✭ 75 (+8.7%)
Mutual labels:  amplify, appsync
enjoytheshow
Real-time facial expression gathering
Stars: ✭ 32 (-53.62%)
Mutual labels:  amplify, appsync
aws-serverless-fullstack-swift-apple-carplay-example
This application demonstrates a full-stack Apple CarPlay app that uses Swift for both the UI and the backend services in AWS. The app accesses Lambda functions written in Swift and deployed from Docker images. The app accesses Amazon Location Service and a 3rd party weather api to display information in the vicinity of the user.
Stars: ✭ 84 (+21.74%)
Mutual labels:  amplify, appsync
study-amplify-with-react-native
AWSKRUG Community Day 2020 Amplify Keynote and Demo
Stars: ✭ 15 (-78.26%)
Mutual labels:  amplify
cognito-amplify-custom-auth
A React/Redux web application that implements a custom UI for Cognito Userpool Auth using AWS Amplify
Stars: ✭ 27 (-60.87%)
Mutual labels:  amplify
amazon-ivs-chime-messaging-ugc-demo
This demo is designed to educate people who want to build live streaming platform with chatting feature. This demo is implemented using Amplify with Amazon IVS, ChimeSDK Messaging.
Stars: ✭ 20 (-71.01%)
Mutual labels:  amplify
Aws Mobile Appsync Sdk Ios
iOS SDK for AWS AppSync.
Stars: ✭ 231 (+234.78%)
Mutual labels:  appsync
amplify-nuxt
Video series code for how to setup AWS Amplify with a Nuxt project
Stars: ✭ 27 (-60.87%)
Mutual labels:  amplify
titanium-turbo
Axway Amplify module that adds some enhancements for Appcelerator Titanium Alloy
Stars: ✭ 15 (-78.26%)
Mutual labels:  amplify
amplify-material-ui
A Material-UI based implementation of aws amplify
Stars: ✭ 32 (-53.62%)
Mutual labels:  amplify
photo-sharing-website
Static pre-rendered photo-sharing website
Stars: ✭ 33 (-52.17%)
Mutual labels:  amplify
amplify-ios-getting-started
This is the editable material for Amplify's iOS Getting Started guide.
Stars: ✭ 20 (-71.01%)
Mutual labels:  amplify
graphql-ttl-transformer
♻ Enable DynamoDB's time-to-live feature to auto-delete old entries in your AWS Amplify API!
Stars: ✭ 75 (+8.7%)
Mutual labels:  amplify
AWS Stripe-SaaS-quickstart
🛍️ 🚀 AWS Software as a Service App with subscriptions using Stripe Quickstart
Stars: ✭ 30 (-56.52%)
Mutual labels:  amplify
Heard
React Native Enterprise Social Messaging App
Stars: ✭ 234 (+239.13%)
Mutual labels:  appsync
transform-graphql
⚙️ Transformer function to transform GraphQL Directives. Create model CRUD directive for example
Stars: ✭ 23 (-66.67%)
Mutual labels:  amplify
griffin-app-opensource
The Axway Griffin App goes open source!
Stars: ✭ 19 (-72.46%)
Mutual labels:  amplify
amplify-ui
A multi-framework Design System to provide a solid foundation for building UI!
Stars: ✭ 487 (+605.8%)
Mutual labels:  amplify
amplify-codegen-ui
Generate React components for use in an AWS Amplify project.
Stars: ✭ 14 (-79.71%)
Mutual labels:  amplify

File uploads and downloads with React, AWS Amplify, AWS AppSync, and Amazon S3

This is an example project showing how to upload and download files and images using AWS Amplify, AWS AppSync, and Amazon S3

How to upload files and images with GraphQL

This project goes along with the GraphQL Tutorial - How to Manage Image & File Uploads & Downloads with AWS AppSync & AWS Amplify on Dev.to.

The question

How do I upload images and files using GraphQL with AWS AppSync?

The solution

There are a few parts to this solution:

  • You must first upload the image to a storage solution (in this example, Amazon S3)
  • After you have finished uploading the image, you will need to store a reference to this image in a database using a GraphQL mutation.
  • When you want to view a public image (public bucket), you need to:
    • Query the image URL from your database using GraphQL
  • When you want to view a private image (non-public bucket), you need to do two things:
    • First, query the image reference from your database using GraphQL
    • Get a signed URL for the image from S3

In this example, I show how to:

  1. Store images using GraphQL, AppSync, and S3 (both using public and private access)
  2. Fetch a list of images and render them in a React application
  3. Fetch a single image and render it in a React application

To deploy this app

Amplify CLI

  1. Clone the project and change into the directory
git clone https://github.com/dabit3/react-amplify-appsync-files-s3.git

cd react-amplify-appsync-s3
  1. Install the dependencies
npm install

# or

yarn
  1. Initialize and deploy the amplify project
amplify init

amplify push
  1. Run the app
npm start
  1. Change the bucket policy in your S3 bucket for files in the images folder to be public (in order for the Product images to be publicly viewable):
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::<YOUR_BUCKET_NAME>/public/images/*"
        }
    ]
}
  1. Render either the private (Users) or public (Products) example in src/App.js:
import React from 'react'
import Products from './Products'
import Users from './Users'

function App() {
  return (
    <Users />
    // or <Products />
  )
}

export default App;

Amplify Console

Click the button to deploy this application to the Amplify console.

amplifybutton

Then change the bucket policy in your S3 bucket for files in the images folder to be public (in order for the Product images to be publicly viewable):

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::<YOUR_BUCKET_NAME>/public/images/*"
        }
    ]
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].