Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant convert using buffer #20

Closed
agustinp93 opened this issue Sep 14, 2020 · 7 comments
Closed

Cant convert using buffer #20

agustinp93 opened this issue Sep 14, 2020 · 7 comments

Comments

@agustinp93
Copy link

Hi,
I tried the convert office file passing buffer but I have no response.

Im downloading a file from s3 (uint8array) converting it to arraybuffer and using:

const toPDF = pipe(
        gotenberg("http://localhost:3000"), 
        convert,
        office,
        set(filename("result.pdf")),
        please
      );
const pdf = await toPDF({ "document.docx": resp.Body.buffer });

Any way to check if the api is up with the ping request? I didnt see it on the doc

@yumauri
Copy link
Owner

yumauri commented Sep 14, 2020

Hello, @agustinparamio !

There is, actually!
I didn't focus on it, though, so if you are using TypeScript — you have to give it empty source.
It is not required in plain JavaScript.

import { gotenberg, pipe, ping, please } from 'gotenberg-js-client'

// ...

pipe(
  gotenberg('http://localhost:3000'),
  ping,
  please
)({}) // <- empty source object to satisfy typings
  .then(() => console.log('Gotenberg is up'))
  .catch((error) => console.error('Gotenberg is down:', error))

Ping request returns nothing (Promise<void>), so in async-await syntax it could be smth like this:

try {
  await pipe(gotenberg('http://localhost:3000'), ping, please)({})
  console.log('Gotenberg is up')
} catch (error) {
  console.error('Gotenberg is down:', error)
}

Do you have any errors on your or Gotenberg sides?

@agustinp93
Copy link
Author

agustinp93 commented Sep 15, 2020

Hi @yumauri, thank you for the answer.

I tried some versions of the following code but I couldn't fix the error I got..

try {
  await pipe(gotenberg('http://localhost:3000'), ping, please)({})
  console.log('Gotenberg is up')
} catch (error) {
  console.error('Gotenberg is down:', error)
}

and got this error
index.js:1437 Gotenberg is down: TypeError: The "listener" argument must be of type Function. Received type object

also tried using an axios request but im blocked by cors policy and from what I can see on gotemberg doc i cant change that.

gotenberg cant be used from react?
any advice?

@yumauri
Copy link
Owner

yumauri commented Sep 15, 2020

Hm, I'm a bit cautious of you mentioning "cors policy" — are you trying to use this client from the browser or I misunderstood that?

@agustinp93
Copy link
Author

yes, im trying to use it from a react app

@yumauri
Copy link
Owner

yumauri commented Sep 15, 2020

Unfortunately, for now this is only server-side client, for Node.js :(

Technically it is possible (I hope) to adopt it for browser also, I created issue #2 for that long ago, but as for now there are some node specific functions and classes are used, and it is impossible to use this library out-of-the box in the browser, sorry.

I will appreciate for PR to add isomorphic features in this package :)

Also, you are the first, trying to use this client from the browser, there wasn't any real demand for that. Now, I think, I'll try to spare some time for that task in near future.

(But you will have to deal with CORS anyways, with or without my library, if Gotenberg is deployed on a different origin).

@agustinp93
Copy link
Author

Thank you @yumauri , will try something else then

@yumauri
Copy link
Owner

yumauri commented Sep 15, 2020

Related to CORS, as far as I understand, official Gotenberg position is that you should add some proxy (Nginx for example) before Gotenberg instance, where you can easily add CORS headers.
See gotenberg/gotenberg#62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants