Aws-sdk-ios: Upload file to S3 via AppSync?

Created on 20 Mar 2019  路  9Comments  路  Source: aws-amplify/aws-sdk-ios

I'm trying to transfer files in both directions from S3. The Amplify documentation implies that you only have to add a S3Object type and the transfers will work via AppSync automatically.

type S3Object { bucket: String! region: String! key: String! }

Once I add this there is a S3ObjectInput method generated

S3ObjectInput(bucket:, region:, key:, localUri:, mimeType:)

I would expect that I can use this method to define the file that I want to send to S3 and then include it in the mutation. However I'm not able to get this to work. When the mutation is executed, the completion handler is never called.

The documentation about this is thin. Could some one point me to an example of how this should work or explain what the process is for transferring to S3 via AppSync. If there is any 3rd party tutorials that would be helpful as well.

Thanks

appsync bug documentation requesting info

Most helpful comment

Thanks for following up. My issue has progressed slightly an I can now provide more info. What I'm seeing is identical to this issue:

https://github.com/aws-amplify/amplify-cli/issues/768

I'm stuck right now with the problem that I try to initialize AWSAppSyncClientConfiguration as such:

self.appSyncConfig = try AWSAppSyncClientConfiguration(appSyncServiceConfig: AWSAppSyncServiceConfig(),databaseURL: databaseURL,s3ObjectManager: AWSS3TransferUtility.default())

The documentation here: https://aws-amplify.github.io/docs/cli/graphql?sdk=ios in the "S3 Objects" section say to use AWSS3TransferUtility.default(). However this results in the wrong type since a AWSS3ObjectManager type is needed. I'm unable to find anywhere in the code how to create an object conforming to the AWSS3ObjectManager protocol. I'm assuming that the documentation is outdated??

All 9 comments

Hi @edfinegan ,

Can you provide a code snippet of how you are using the APIs? as well as some logs during the transaction? We will be able to diagnose this issue better.

Thanks for following up. My issue has progressed slightly an I can now provide more info. What I'm seeing is identical to this issue:

https://github.com/aws-amplify/amplify-cli/issues/768

I'm stuck right now with the problem that I try to initialize AWSAppSyncClientConfiguration as such:

self.appSyncConfig = try AWSAppSyncClientConfiguration(appSyncServiceConfig: AWSAppSyncServiceConfig(),databaseURL: databaseURL,s3ObjectManager: AWSS3TransferUtility.default())

The documentation here: https://aws-amplify.github.io/docs/cli/graphql?sdk=ios in the "S3 Objects" section say to use AWSS3TransferUtility.default(). However this results in the wrong type since a AWSS3ObjectManager type is needed. I'm unable to find anywhere in the code how to create an object conforming to the AWSS3ObjectManager protocol. I'm assuming that the documentation is outdated??

@edfinegan Sorry for the delayed response. Have you run the following command to generate the S3ObjectWrapper that creates an extension of AWSS3TransferUtility to confirm to the AWSS3ObjectManager protocol?

aws-appsync-codegen generate GraphQLOperations/posts.graphql --schema GraphQLOperations/schema.json --output API.swift --add-s3-wrapper

@kvasukib how to I use this with the amplify codegen? Adding --add-s3-wrapper doesn't seem to do anything. Also, do I then manually have to add resolvers to get this file upload to work?

@edfinegan did you get this to work in the end? Any pointers would be much appreciated.

Classifying this as a Doc bug.

Notes:

  • There are currently multiple layers of indirection between the S3Object and S3ObjectInput, the generated model, the S3ObjectProtocol, and the actual S3 implementations. These layers are an attempt to provide library support for complex objects in the core code, but to avoid requiring the import of the AWSS3 library until an app actually decides to use complex objects. We should clarify that relationship and make it very explicit what a customer has to do to use complex objects.

  • There are a couple of places that talk about using S3 objects with AppSync, and they have conflicting information. We need to standardize them.

  • For now, we have a file named `(S3ObjectWrapper.swift)[https://github.com/awslabs/aws-mobile-appsync-sdk-ios/blob/master/AWSAppSyncTestCommon/S3ObjectWrapper.swift] that is part of our test library that you can copy into your main codebase. Need to test if that's still usable and/or required, and provide documentation on how to use it.

  • Need to clearly call out that complex object uploads will need to have the appropriate access level ("private/", "protected/", or "public/") prepended to the key.

I merged a PR (aws-amplify/docs/pull/836) to the documentation site to clarify how the integration between the AppSync client and the required protocols (AWSS3ObjectManager, AWSS3ObjectProtocol and AWSS3InputObjectProtocol) is done.

Check https://aws-amplify.github.io/docs/ios/storage#usage-with-graphql-apis-complex-objects for more details and let us know if that's helpful.

I'm having the same issues, but with the Javascript / React Native SDK. My Issue is that the generated schema for the s3ObjectInput does not include the localUri and mimeType which results in mutation errors.

Generated

input S3ObjectInput {
  bucket: String!
  key: String!
  region: String!
}

@coreybrown89 Please open an issue on the JS repo -- that team will have much more experience dealing with issues on that platform.

Was this page helpful?
0 / 5 - 0 ratings