Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files variable type #3

Open
sandervanhooft opened this issue Dec 4, 2016 · 5 comments
Open

Files variable type #3

sandervanhooft opened this issue Dec 4, 2016 · 5 comments

Comments

@sandervanhooft
Copy link
Collaborator

@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.

@thebigredgeek
Copy link
Collaborator

@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

@sandervanhooft
Copy link
Collaborator Author

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

@sandervanhooft
Copy link
Collaborator Author

@HriBB @thebigredgeek How about accepting an array of Files (array) as input?

Given the MDN description there seems to be no way to programmatically create a FileList.

@HriBB
Copy link
Owner

HriBB commented Dec 7, 2016

@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 Files.

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

@sandervanhooft
Copy link
Collaborator Author

I'll try to look into it. Good luck with your presentation :)

sandervanhooft added a commit to sandervanhooft/apollo-upload-network-interface that referenced this issue Dec 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants