apollo-upload-network-interface
apollo-upload-network-interface copied to clipboard
Files variable type
@HriBB @thebigredgeek
What type should the files variable be when passed to the mutation?
The file upload works fine when using your example code. But when using react-dropzone or tcomb-form the files seem to be not handled appropriately.
@sandervanhooft you have to send files as form data. https://github.com/okonet/react-dropzone doesn't appear to have any opinions as to how you send the data, they just provide hooks to receive the dropped files via callbacks
Hi @thebigredgeek,
I have tried the following, but it didn't work:
// in component that uses react-dropzone:
onDrop: function (acceptedFiles, rejectedFiles) {
console.log('Accepted files: ', acceptedFiles) // console.log: [File]
const { onUpload, token, offerid } = this.props
const fd = new FormData()
acceptedFiles.map( file => fd.append('files', file, file.name) )
onUpload(token, offerid, fd)
console.log('Rejected files: ', rejectedFiles) // console.log: []
},
The onUpload
mutation is received by the server, but yields an empty object for the files
variable. What am I missing?
Kind regards,
Sander
@HriBB @thebigredgeek How about accepting an array of Files (array<File>) as input?
Given the MDN description there seems to be no way to programmatically create a FileList.
@sandervanhooft take a look at this line. I am checking for the presence of FileList
. There we need to add additional check for a single File
or array or File
s.
I am busy ATM, I have a presentation about React and GraphQL at the office in a few hours, hopefully after that I will have more time to fix these issues. You are welcome to make a PR for this ;)
I'll try to look into it. Good luck with your presentation :)