![]() I would have to create a getProfilePicture root query to get around this. However, this prevents us from using the same code for all profile picture requests, and the profilePicture is hooked to the User type, not the me() query. We can, of course, read the identity of the user from the $context.identity. That means $ does not exist, and the URL construction will fail. We aren’t requesting any other fields, so nothing is passed down to the resolver of the profilePicture field. Now, how does that affect the context of the request? The $context.source is a blank object because we are not asking for any other fields. This is a perfectly reasonable request - give me the download URL of my profile picture. It does, however, show off one problem that is an issue with GraphQL. You might think that this is a great way to get the profile picture. We can also use the same mechanism to generate a pre-signed URL for the getObject operation. I can now do a PUT to the uploadUrl from my client using standard HTTP clients to upload a new picture. ![]() To accomplish this, I have expanded my GraphQL schema as follows: It is not without its drawbacks (for example, all pre-signed URLs will expire and multi-part uploads are particularly problematic with pre-signed URLs), but for this use case, they are a great option. The client app then uploads the file to the pre-signed URL.Ī pre-signed URL is used to grant a user temporary credentials to perform an action on S3, such as to upload or download a file.A pre-signed URL grants temporary permissions for the operation. AWS AppSync invokes an AWS Lambda function to generate a pre-signed URL for upload purposes and returns it to the client.The client app asks AWS AppSync (via GraphQL) for an upload URL.Any user can download a profile picture, but only the owner of a profile can upload the profile picture. To do this, I’m going to implement a feature - profile pictures - in my Restaurant Reviews app. In this article, I’m going to present one way that you can handle the upload and download of files whereby the URL of the files are presented via GraphQL using AWS AppSync and the actual upload / download of the files are done via HTTP. ![]() Which isn’t to say that GraphQL does not have a role to play within file handling - just that the upload and download of files needs to be done outside the confines of GraphQL. It may seem an obvious statement, but it needs to be said. ![]()
0 Comments
Leave a Reply. |