Search code examples
graphqlaws-appsyncaws-amplify

Upload image with AWS Amplify Appsync in React


I have a react project set up with AWS Amplify and Appsync.

I am using the GraphQL functionality in Amplify to interface with AppSync.

I am trying to upload an image to S3 from the react app. Has anyone done this through Amplify GraphQL? Could you please help?

BTW, I have read the documentation about how to do this with Apollo and aws-appsync-react. I am trying to figure out how to do with the GraphQL functionality built into Amplify.


Solution

  • I think right now it is not possible to upload complex object via Amplify.API as for uploading with AppSync you need to submit complexObjectsCredentials to AppSync client.

    const client = new AWSAppSyncClient({
        url: ENDPOINT,
        region: REGION,
        auth: { .. },
        complexObjectsCredentials: () => Auth.currentCredentials(),
    });
    

    And it seems you cant provide those credentials when configuring amplify.

    Alternatively you could use 'Amplify.Storage' module to upload files without AppSync