I'm trying to upload an image and return it's id with the following code:
export function uploadImage(file: any, location: string, next: any): Promise<string> { try { if (!file) { throw new Error("No Image file"); } const id = location + "/" + utilities.generatePushID(); const options = { resource_type: "raw", public_id: id, }; return cloudinary.uploader.upload_stream(options, (error: any, result: any) => { if (error) { throw new Error("Couldn't upload"); } return result.public_id; }).end(file.buffer); } catch (err) { return next(InternalError(err)); } }
However, whenever I try to call the function, it gives me back an UploadStream object rather than the string that I want. It's as if it immediately returns the uploader, rather than the result of the uploader. Why?
#javascript #node-js #typescript