apollo-server-express#GraphQLUpload TypeScript Examples
The following examples show how to use
apollo-server-express#GraphQLUpload.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: image-resolver.ts From convoychat with GNU General Public License v3.0 | 6 votes |
@UseMiddleware(RateLimit({ limit: 10 }))
@Mutation(() => UploadImageOutput)
async uploadImage(
@Arg("file", () => GraphQLUpload) file: Promise<IUpload>
): Promise<UploadImageOutput> {
const { createReadStream } = await file;
const fileStream = createReadStream();
return new Promise((resolve, reject) => {
const cloudStream = cloudinary.uploader.upload_stream(
{
unique_filename: true,
folder: process.env.MEDIA_FOLDER,
},
(err, fileUploaded) => {
if (err) reject(false);
resolve({
url: fileUploaded.secure_url,
public_id: fileUploaded.public_id,
});
}
);
fileStream.pipe(cloudStream);
});
}