Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Specify value for custom fields on the File type when uploading files #55

Open
marktani opened this issue Jan 22, 2018 · 8 comments
Open

Comments

@marktani
Copy link
Contributor

Issue by sedubois
Monday Apr 17, 2017 at 13:08 GMT
Originally opened as https://github.com/graphcool/prisma/issues/174


Currently I know of these two ways to upload files:

  • drag and drop onto data browser (nice!)
  • curl -X POST

But in both cases, AFAIK there's no way to assign at the same time some extra data (e.g I added a category field) or specify the filename. This would be quite useful when bulk uploading files.

@marktani
Copy link
Contributor Author

Comment by marktani
Monday Apr 17, 2017 at 13:38 GMT


You can specify the file name when using fetch, as shown in this tutorial.

form.append('data', body, {
  filename: fileName
})

currently, addititional fields on the file node need to be updated after the file has been uploaded using updateFile:

mutation {
  updateFile(
    id: "some-id"
    category: "my category"
  ) {
    id
  }
}

@marktani
Copy link
Contributor Author

Comment by sedubois
Monday Apr 17, 2017 at 14:01 GMT


Thanks. But if I need to change after upload, I can as well just change in the data browser.

It would just be great to avoid the extra step.

Also about specifying the filename, is there any way to do that using curl? A one-liner bash command is much more convenient than creating a whole project.

@marktani
Copy link
Contributor Author

Comment by marktani
Monday Apr 17, 2017 at 18:57 GMT


This uploads your local file example.png with the new file name myname.png

curl -X POST 'https://api.graph.cool/file/v1/__PROJECT_ID__' -F "data=@example.png;filename=myname.png"

I updated the line in the docs to reflect this :)

@marktani
Copy link
Contributor Author

Comment by sedubois
Wednesday Apr 19, 2017 at 14:28 GMT


Thanks @marktani that's helpful 🙂

Would also be nice to specify custom fields that way:

curl -X POST 'https://api.graph.cool/file/v1/__PROJECT_ID__' -F "data=@example.png;filename=myname.png;category=myCategory"

If the field has another type than String (e.g numeric), it could be parsed the same way as is done in the console when typing values with the keyboard there.

@marktani
Copy link
Contributor Author

Comment by kbrandwijk
Monday Jun 05, 2017 at 12:41 GMT


+1 for file upload with additional metadata in a single request.

@marktani
Copy link
Contributor Author

Comment by patoncrispy
Wednesday Jun 21, 2017 at 07:47 GMT


I would also love to see something like this. Adding other metadata to the body of the request shouldn't be too tricky, right?

@marktani
Copy link
Contributor Author

Comment by kbrandwijk
Wednesday Jun 21, 2017 at 22:17 GMT


Please checkout my metadata-file-proxy example: https://github.com/kbrandwijk/functions/tree/file-proxy/file-proxy for a workaround until we get out of box support for this in the Graphcool File API. You can strip out some functionality if you just need the upload with metadata.

@marktani
Copy link
Contributor Author

Comment by lucfranken
Friday Jun 23, 2017 at 11:44 GMT


Agree this is important. It will otherwise also leave a chance that you get stuck with invalid data like orphan uploads where the mutation afterwards did not succeed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant