How to upload images to Digital Ocean Spaces?

I am using GraphQL for creating APIs

type Mutation {
    uploadImage(image: Upload!): Image

I am using Upload scalar.

In the frontend, getting the file from the input field.

const filePickerPath = async e => {
    const file =[0]

      variables: {
        image: file
    }).then(response => {
    }).catch(error => {

Calling the uploadImage mutation by passing the File constructor as a variable.

Inside the uploadImage resolver, after getting the data input (argument).

const data = { ...input.image.file }

console.log("Spaces start");
const params = {
  Bucket: process.env.DO_SPACES_BUCKET,
  Key: path,
  Body: data,
  ACL: "public-read"

spaces.putObject(params, (error, data) => {
  if (error) {
    console.error("Error: uploadImage");
    console.log(error, error.stack);
  else {
console.log("Spaces end");

After that I get this error

Expected params.Body to be a string, Buffer, Stream, Blob, or typed array object

I even tried convert the data input as a Buffer but that didn't work either.

No Comments Yet