简体   繁体   English

如何使用AWS Amplify GraphQL Client将文件上传到S3

[英]How to use AWS Amplify GraphQL Client to upload files to S3

Here is the official documentation for AWS Amplify GraphQL Client: https://aws-amplify.github.io/amplify-js/media/api_guide.html . 这是AWS Amplify GraphQL Client的官方文档: https ://aws-amplify.github.io/amplify-js/media/api_guide.html。 The section supplies an example for basic String inputs though. 本节提供了基本String输入的示例。

For AWS Mobile Appsync SDK for Javascript , there is a detailed doc here: https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-react.html . 对于适用于Java的AWS Mobile Appsync SDK ,此处有详细的文档: https : //docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-react.html However, I do not want to add another configuration for it -I already have one for Amplify. 但是,我不想为其添加其他配置-我已经有一个用于Amplify的配置。

So, how to upload files to S3 storage by using AWS Amplify and AWS AppSync as the backend, what extra configuration is needed for Amplify -if there is? 那么,如何通过使用AWS Amplify和AWS AppSync作为后端将文件上传到S3存储,Amplify需要什么额外的配置-如果有的话?

Http Endpoints are added as an option to be used as datasources to AppSync schemata, but as of time, there is no S3 bucket as an option. Http端点作为选项被添加为用作AppSync架构的数据源,但是截至目前,没有S3存储桶作为选项。 There are solutions like [this]( https://stackoverflow.com/a/50218870/4636715 ), but they require AWSAppSyncClient at Javascript side which would add complexity to the client code as Amplify is set up there already imho. 有类似[this]( https://stackoverflow.com/a/50218870/4636715 )的解决方案,但是它们要求Javascript端使用AWSAppSyncClient ,这会增加客户端代码的复杂性,因为已经在此处设置了Amplify。

So, I ended up with using Storage of AWS Amplify -independent of AppSync. 因此,我最终使用了独立于AppSync的AWS Amplify的Storage Then, I wait for the upload to be successful and call an AppSync mutation to store the key for the uploaded file in DynamoDB using regular datasource resolvers. 然后,我等待上载成功,并调用AppSync突变,以使用常规数据源解析器将上载文件的密钥存储在DynamoDB中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM