I'm trying to upload a file from Angular using nodejs, express and graphql-upload. I coded and when I try to upload, my server says that createreadstream is not a function and I don't know where is the problem. I watched the same questions but older. Please somebody can help me? If you need more information, please, let me know. I'm' junior asking. Thank you in advance
Nodejs version 14.13.1
Grapql-upload latest
typescript
My code is the next one:
Mutations.ts
import { IResolvers } from 'graphql-tools';
import fs from 'fs'
import { processUpload } from '../../lib/upload';
const resolversColorMutation: IResolvers = {
Mutation: {
singleUpload: (_, { file }, { cloudinary }) => processUpload(file, cloudinary)
}
}
export default resolversColorMutation
upload.ts
const storeFyleSystem = ({ stream, filename }: any, userId: string) => {
const path = `${UPLOAD_DIR}/${filename}`;
const id = userId;
return new Promise((resolve, reject) =>
stream
.on('error', (error: any) => {
if (stream.truncated) {
// Delete the truncated file.
// Borar el fichero local
fs.unlinkSync(path);
}
reject(error);
})
.pipe(fs.createWriteStream(path))
.on('error', (error: any) => reject(error))
.on('finish', () => resolve({ id, path }))
);
};
const UPLOAD_DIR = './uploads';
export const processUpload = async (upload: any, cloudinary: any) => {
mkdirp.sync(UPLOAD_DIR);
const { createReadStream, filename, mimetype } = await upload;
**const stream = createReadStream()**;
const { id, path }: any = await storeFyleSystem({ stream, filename }, 'theName');
fs.unlinkSync(path);
return { id, path, filename, mimetype};
};
question from:
https://stackoverflow.com/questions/65873980/createreadstream-is-not-a-function-graphql-upload 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…