DEV Community

Discussion on: Node.js : Upload binary image "on-the-fly" with Fastify and Cloudinary

Collapse
 
suntong profile image
suntong

Thanks for the most helpful write up.

Would it be possible to put your full code somewhere please?

I don't know TypeScript and I tried to make the above code work by first following freecodecamp.org/news/learn-typesc...

However, this is what I get when run tsc index.ts:

   index.ts:21:1 - error TS1434: Unexpected keyword or identifier.

    21 async uploadProfilePicture(req, res): Promise<string> {
       ~~~~~

    index.ts:21:37 - error TS1005: ';' expected.

    21 async uploadProfilePicture(req, res): Promise<string> {
                       ~

    index.ts:22:9 - error TS1005: ':' expected.

    22   const binaryData = req.file.buffer
           ~~~~~~~~~~

    index.ts:23:3 - error TS1005: ',' expected.

    23   const result = await uploadPicture(binaryData) // Watch below for details
     ~~~~~

    index.ts:23:9 - error TS1005: ':' expected.

    23   const result = await uploadPicture(binaryData) // Watch below for details
           ~~~~~~

    index.ts:24:3 - error TS1005: ',' expected.

    24   return result.url
     ~~~~~~

    index.ts:24:10 - error TS1005: ':' expected.

    24   return result.url
        ~~~~~~

    index.ts:32:22 - error TS1005: ',' expected.

    32 uploadPicture(content: Buffer): Promise<object> {
                ~

    index.ts:32:31 - error TS1005: ';' expected.

    32 uploadPicture(content: Buffer): Promise<object> {
                     ~

    index.ts:33:10 - error TS1005: ':' expected.

    33   return new Promise((resolve, reject) => {
Enter fullscreen mode Exit fullscreen mode

My use case is written in Typescript, but the equivalent can be done with standard Javascript.

If a corresponding standard Javascript version could also be provided, that'd be more appreciated.

Thanks!