Prisma1: Specify value for custom fields on the File type when uploading files

Created on 17 Apr 2017  路  9Comments  路  Source: prisma/prisma1

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.

Most helpful comment

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

All 9 comments

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

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.

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 "[email protected];filename=myname.png"

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

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 "[email protected];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.

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

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

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.

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schickling picture schickling  路  3Comments

ragnorc picture ragnorc  路  3Comments

thomaswright picture thomaswright  路  3Comments

tbrannam picture tbrannam  路  3Comments

marktani picture marktani  路  3Comments