# File uploads
With Buoy, you can upload files to your backend through a mutation.
Just define the variables to contain the files your want to upload.
Supported types are File
(opens new window) FileList
(opens new window) and
Blob
(opens new window).
# Preparing your backend
Your backend must support the graphql-multipart-request-spec (opens new window). Lighthouse supports this out-of-the-box in the master branch. Follow their guide to enable file uploads (opens new window) in your schema.
# Uploading a file
In order to upload files, simply add them as variables.
Example:
public uploadFile(): void {
this.buoy.mutate(
gql `
mutation ($file: Upload!) {
shareFile(file: $file) {
url
}
}
`,
{
// Pick the first file form file-input
file: this.file.nativeElement.files[0]
},
{
scope: 'shareFile'
}
).toPromise().then(
(success) => {
console.log('File was uploaded, and is available at:', success.url);
},
(error) => {
console.log('ERROR', error);
}
);
}