dimer47 / node-ovh-objectstorage

Creative Commons Attribution Share Alike 4.0 International
12 stars 11 forks source link

Help needed with object.get() #26

Closed onicolet closed 2 years ago

onicolet commented 2 years ago

Hi!

Awesome lib!

I'm just needing a bit of help with the object.get() function.

The response i'm getting is something like:

{ content: xxxxxxxxx headers: {.....} }

I'm having difficulties sending my file to my frontend... What format is content ? What should i do ? I'm using NestJs@8

Thanks in advance, and again, awesome work,

Vive la france

onicolet commented 2 years ago

By looking at the source code, i found this

@param {String|null|undefined} encoding If null, the body is returned as a Buffer by default it is utf8.

So my final code is:


    let fileFetched = await storage.objects().get(path, null);

    res.set({
      'Content-Type': documentMimeType,
      'Content-Disposition': 'attachment; filename= documentName',
    });

    return new StreamableFile(Buffer.from(fileFetched.content));

Thanks, have a great day