-
Notifications
You must be signed in to change notification settings - Fork 5
Example for handling file on server #4
Copy link
Copy link
Open
Description
@HriBB Do you perhaps have an example how to handle the file on the graphql server?
If I forward it to my REST endpoint, it doesn't seem to be recognised as a file.
My resolver:
...
uploadUserAvatar(root: Function, args: Object) {
console.log(args.files) // see output below
Viewer.uploadAvatar(args.token, args.files[0])
return Viewer.fromToken(args.token)
}
...
Viewer connection:
uploadAvatar(token: string, avatar: Object){
const options = {
method: 'POST',
uri: this.buildRestURL('settings/profile/uploadavatar'),
headers: {
'Authorization': `Bearer ${token}`,
},
body: {
avatar,
},
json: true,
}
return rp(options)
.then((res) => {
console.log("\nuploadAvatar SUCCESS:", res)
return {
...res.data,
token
}
})
.catch((err) => console.log("\nuploadAvatar ERROR:", err))
Console.log(args.files) from resolver:
[ { fieldname: 'files',
originalname: 'elephant.jpeg',
encoding: '7bit',
mimetype: 'image/jpeg',
destination: '../tmp/',
filename: '5b4af2fa02e1cfde3995873a2d7ea959',
path: '../tmp/5b4af2fa02e1cfde3995873a2d7ea959',
size: 3536 } ] }
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels