I am trying out uploading images using apollo-upload-client, graphql and cloudinary,
Goal: To successfully upload image to cloudinary, get the cloudinary url and insert into database
Present: Don't get any error message yet don't see file uploaded to cloudinary
Help: Is my code below correct? Anyone has successfully implemented solution with apollo-client-upload, graphql and cloudinary in their code? How to get the response url from cloudinary which I can insert into my db
So far, i have tested with uploading to our own local server and the code works fine. I have isolated and the error likely comes from below portion
Thanks in advance
export const cloudinaryUpload = async ({ stream }: any): Promise<string> => {
console.log("stream upload gql ", stream);
cloudinary.config({
cloud_name: process.env.cloud_name,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET
});
cloudinary.uploader
.upload_stream({ resource_type: "raw" }, function(error: any, result: any) {
console.log("error ", error);
console.log("result ", result);
})
.end(stream.buffer);
return `Test`;
};
export const processUpload = async (upload: any) => {
const { stream } = await upload;
const { id } = await storeUpload({ stream });
return `id`;