Closed Akifcan closed 3 years ago
Hello i tried upload file with graphql-upload package but i have this error.
BadRequestError: Misordered multipart fields; ‘map’ should follow ‘operations’ (https://github.com/jaydenseric/graphql-multipart-request-spec). at Busboy.<anonymous> (C:\Users\user\Desktop\grap\node_modules\graphql-upload\public\processRequest.js:175:17)
i found your solution on stackoverflow (https://stackoverflow.com/questions/62569041/graphql-upload-getting-invalid-json-in-the-operations-multipart-field) and tried but still doesn't work
this is my client request
document.querySelector('form').addEventListener('submit', e => { e.preventDefault() const file = document.querySelector('input').files[0] const formData = new FormData() formData.append("query", "{ 'query': 'mutation($file: Upload!) { uploadFile(file: $file) }', 'variables': { 'file': null } }") formData.append("map", "{ 'nfile': ['variables.file'] }") formData.append("nfile", file) fetch('http://localhost:3000/graphql', { method: 'POST', body: formData }) .then(r => r.json()) .then(data => console.log('data returned:', data)); })
and backend
@Mutation(() => Boolean) async uploadFile(@Args({name: 'file', type: () => GraphQLUpload}) { createReadStream, filename }: FileUpload): Promise<boolean> { return new Promise(async (resolve, reject) => createReadStream() .pipe(createWriteStream(`./uploads/${filename}`)) .on('finish', () => resolve(true)) .on('error', () => reject(false)) ); }
There are a few errors:
"
'
formData.append("query",
operations
Hello i tried upload file with graphql-upload package but i have this error.
i found your solution on stackoverflow (https://stackoverflow.com/questions/62569041/graphql-upload-getting-invalid-json-in-the-operations-multipart-field) and tried but still doesn't work
this is my client request
and backend