starter
starter copied to clipboard
Upload avatar
This is a work in progress PR for adding avatar upload functionality, merging #101 and #108. It's no-where near ready.
- [x] Add createSignedUrl mutation
- [x] Add upload component
- [x] Render profile page in two sections - one for avatar, one for textual settings
- [x] Handle errors during avatar upload flow
- [ ] Document how to configure IAM, S3, etc for uploads
- [ ] Allow configuring the system to not allow avatar uploads (e.g. if you don't want the S3 faff)
- [ ] Uploads should be private and expire automatically after a few hours
- [ ] The uploaded URL should be sent to the server, validated, and then the object should be moved to public S3 that doesn't expire, and referenced in the DB so that it may later be safely deleted (beware of race conditions)
- [ ] A trigger should be added such that when a new upload is performed, the old upload gets queued for deletion
- [ ] Storage needs to be added to the database to track the uploads the user has permissions to delete
Unfortunately I timed out after 4 hours merging these PRs and attempting to implement the above functionality.
I tried running with a minio server, which you can run with something like:
mkdir /tmp/s3
docker run -p 9000:9000 --name minio1 \
-v /tmp/s3:/data \
minio/minio server /data
Then adding S3_UPLOADS_BUCKET=http://localhost:9000/uploads to my .env file.
But then, while trying to upload a file I get this error in the javascript console:
[GraphQL error]: message: syntax error at end of input, location: [{"line":2,"column":3}], path: ["createUploadUrl"]
Error: "GraphQL error: syntax error at end of input"
code: "42601"
severity: "ERROR"
I got the same error as the previous commenter - I believe it is something to do with the SAVEPOINT in getCurrentUser not having a name, because changing the 3 queries to be [..] SAVEPOINT create_upload_url gives me a different error:
{
"errors": [
{
"message": "SAVEPOINT can only be used in transaction blocks",
"locations": [
{
"line": 25,
"column": 3
}
],
"path": [
"createUploadUrl"
],
"extensions": {
"exception": {
"code": "25P01",
"severity": "ERROR"
}
}
}
],
"data": {
"createUploadUrl": null
}
}
So when we call getCurrentUser it's not inside a transaction? That's weird because the docs say[0] that all mutations should run under a transaction. Could this be caused by using the wrong version of Postgraphile or Postgres? I'm using the latest version of this starter and Postgres 12
[0] https://www.graphile.org/postgraphile/make-extend-schema-plugin/#querying-the-database-inside-a-resolver
Yes, the savepoint should have a name. The whole getCurrentUser function doesn't currently make sense; e.g. there's no point doing pool.query('savepoint...') because the client you pool.query('release savepoint...') from may not be the same client that created the savepoint.
Basically: this PR is a very WIP merge of two other PRs and is not suitable for usage - that's why it's in draft status.