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

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

Closed
sedubois opened this issue Apr 17, 2017 · 9 comments
Closed

Comments

@sedubois
Copy link

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

marktani commented Apr 17, 2017

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
  }
}

@sedubois
Copy link
Author

sedubois commented Apr 17, 2017

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

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 :)

@sedubois
Copy link
Author

sedubois commented Apr 19, 2017

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.

@kbrandwijk
Copy link
Contributor

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

@marktani marktani changed the title Specify metadata when uploading files Specify value for custom fields on the File type when uploading files Jun 10, 2017
@patoncrispy
Copy link

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

@kbrandwijk
Copy link
Contributor

kbrandwijk commented Jun 21, 2017

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.

@lucfranken
Copy link

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.

@marktani
Copy link
Contributor

This issue has been moved to graphcool/graphcool-framework.

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

No branches or pull requests

6 participants