Function should be returning a promise of a string but doesn't

Function should be returning a promise of a string but doesn't

I'm trying to upload an image and return it's id with the following code:

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

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to Hire Node.js Developers And How Much Does It Cost?

A Guide to Hire Node.js Developers who can help you create fast and efficient web applications. Also, know how much does it cost to hire Node.js Developers.

Top 7 Most Popular Node.js Frameworks You Should Know

Node.js is an open-source, cross-platform, runtime environment that allows developers to run JavaScript outside of a browser. In this post, you'll see top 7 of the most popular Node frameworks at this point in time (ranked from high to low by GitHub stars).

Deno vs Node.js: Deno Will Replace Node.JS?

Deno vs Node.js: Deno Will Replace Node.JS? What’s Deno, and how is it different from Node.js? Node.js is Dead – Long live Deno! The goal of Deno is not to replace Node.js, but to offer an alternative.

Node.js for Beginners - Learn Node.js from Scratch (Step by Step)

Node.js for Beginners - Learn Node.js from Scratch (Step by Step) - Learn the basics of Node.js. This Node.js tutorial will guide you step by step so that you will learn basics and theory of every part. Learn to use Node.js like a professional. You’ll learn: Basic Of Node, Modules, NPM In Node, Event, Email, Uploading File, Advance Of Node.

Hands on with Node.Js Streams | Examples & Approach

The practical implications of having Streams in Node.js are vast. Nodejs Streams are a great way to handle data chunks and uncomplicate development.