Skip to content

Image upload backend implementation

Hannes Heine requested to merge pr636head into pr636base

Created by: Tirokk

roschaefer Authored by roschaefer Merged


This is a curl request from a folder where I have a file avatar.jpg:

curl localhost:4000/ \
  -F operations='{ "query": "mutation($id: ID!, $file: Upload) { UpdateUser(id: $id, avatarUpload: $file) { id name avatar } }", "variables": { "id": "u3", "file": null } }' \
  -F map='{ "0": ["variables.file"] }' \
  -F 0=@avatar.jpg

It uploads the avatar to the public folder.

Same with the posts:

curl localhost:4000/ \
                         -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoidXNlciIsIm5hbWUiOiJKZW5ueSBSb3N0b2NrIiwiZGlzYWJsZWQiOmZhbHNlLCJhdmF0YXIiOiIvdXBsb2Fkcy8xNTU4MzkxOTM0NzcwLWF2YXRhciIsImlkIjoidTMiLCJlbWFpbCI6InVzZXJAZXhhbXBsZS5vcmciLCJzbHVnIjoiamVubnktcm9zdG9jayIsImlhdCI6MTU1ODM5NTc1OSwiZXhwIjoxNjQ0Nzk1NzU5LCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjMwMDAiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjQwMDAiLCJzdWIiOiJ1MyJ9.IAjxXWs7bRMZyCV8c56oDoPRU3vfUED1vwQc3lwPCRA" \
                         -F operations='{ "query": "mutation($id: ID!, $file: Upload) { UpdatePost(id: $id, imageUpload: $file) { id title image } }", "variables": { "id": "9d5b2cab-c447-4e7e-8a57-e58daaba3306", "file": null } }' \
                         -F map='{ "0": ["variables.file"] }' \
                         -F 0=@avatar.jpg

Note that you must be authenticated and it must be your own post.

Pullrequest

Issues

Checklist

  • None

How2Test

  • None

Todo

  • Write tests
  • Change the user.avatar url and send it to /api in the frontend

Merge request reports