How to upload an image to AWS S3 using GraphQL?

前端 未结 2 1074
抹茶落季
抹茶落季 2021-01-02 06:30

I\'m uploading a base64 string but the GraphQL gets hung. If I slice the string to less than 50,000 characters it works. After 50,000 characters, graphQL never makes it to

2条回答
  •  借酒劲吻你
    2021-01-02 07:10

    AWS AppSync (https://aws.amazon.com/appsync/) provides this with functionality known as "Complex Objects" where you can have a types for the S3 Object and the input:

    type S3Object {
        bucket: String!
        key: String!
        region: String!
    }
    
    input S3ObjectInput {
        bucket: String!
        key: String!
        region: String!
        localUri: String
        mimeType: String
    }
    

    You could then do something like this to define this object as part of another type:

    type UserProfile {
        id: ID!
        name: String
        file: S3Object
    }
    

    And then specify a mutation to add it:

    type Mutation {
        addUser(id: ID! name: String file: S3ObjectInput): UserProfile!
    }
    

    Your client operations would need to specify the appropriate bucket, key (with file extension), region, etc.

    More here: https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-react.html#complex-objects

提交回复
热议问题