I am having the following issue with upload images...
# orm-help
a
I am having the following issue with upload images:
Cannot destructure property 'createReadStream' of 'file' as it is undefined.
Copy code
Server is running on <http://localhost:4000>
{
  name: Promise {
    {
      filename: 'bio_alejandro.png',
      mimetype: 'image/png',
      encoding: '7bit',
      createReadStream: [Function: createReadStream]
    }
  }
}
TypeError: Cannot destructure property 'createReadStream' of 'file' as it is undefined.
    at singleUpload (/Users/sancheza/Library/Mobile Documents/com~apple~CloudDocs/Projects/homeinroom/server/src/resolvers/Mutation.js:29:12)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Copy code
async function singleUpload(parent, args, context) {
    console.log(args);
    const userId = getUserId(context);

    const file = await args.file

    const {createReadStream, filename, mimetype} = file;
    const stream = createReadStream();
    stream.pipe(fs.createWriteStream(filename));

    return context.prisma.createFile({ name: filename });
}
why createReadStream is undefined?
a
Check your node version
The API changed I believe
f
You need to
await file
^^ -->
Copy code
const {
  createReadStream,
  filename,
  mimetype,
} = await file;
a
I was doing the await before, the problem was the promise name, now it works finally!
Thanks @Florian @Alex Vilchis