-
Notifications
You must be signed in to change notification settings - Fork 83
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
How to access unoserver via curl? #162
Comments
The server communicates to the client with XMLRPC. You should, in theory, be able to use any XMLRPC client. But I'm not an expert on XMLRPC and internally both the server and client are using Python's XMLRPC library that deals with all the details so I don't have to. The protocol might also change between versions, so I would recommend continuing to use the client to do the conversions. |
Thank you. It's a pity, it would be convenient to contact unoserver via curl, I'll poke around a little more, maybe something will come of it. |
You can write a simple HTTP server on top of the client.
…On Mon, Feb 3, 2025 at 7:44 AM Evgenii Grekov ***@***.***> wrote:
Thank you. It's a pity, it would be convenient to contact unoserver via
curl, I'll poke around a little more, maybe something will come of it.
—
Reply to this email directly, view it on GitHub
<#162 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHNZKKXZRA3UWKCMANKBNL2N5QDTAVCNFSM6AAAAABWL7SYASVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMZQHA2DMNRRGE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Using curl has absolutely no benefit over using the client. Using an XMLRPC library in the language you are programming in would make sense, although I won't recommend it. But using curl, absolutely not. |
You need to use a method like this. You are right, I plan to use it to send a request from a PHP application, that's why I asked how to do it on curl, to test it. curl -X POST http://127.0.0.1:2003 -H "Content-Type: text/xml" --data-binary @- <<EOF
<?xml version="1.0"?>
<methodCall>
<methodName>convert</methodName>
<params>
<param>
<value><nil/></value>
</param>
<param>
<value>
<value><string>base64</string></value>
</value>
</param>
<param>
<value><nil/></value>
</param>
<param>
<value><string>3.pdf</string></value>
</param>
<param>
<value><string>pdf</string></value>
</param>
<param>
<value><nil/></value>
</param>
<param>
<value><nil/></value>
</param>
<param>
<value><boolean>false</boolean></value>
</param>
<param>
<value><nil/></value>
</param>
</params>
</methodCall>
EOF |
Yeah, that seems reasonable. If you look in server.py you can see what the parameters are for the convert methos. The info method will also give you an API version number, that I hope to remember to increase every time the API changes. The client will always first call the info method to check that the server is started, and check that the API version is correct. I suggest you do that as well. |
$file = file_get_contents(Yii::getAlias('@console') . '/runtime/3.docx');
$outputFileName = Yii::getAlias('@console') . '/runtime/output.pdf';
$fileBase64 = base64_encode($file);
$client = new Client("http://unoserver:2003");
$req = new Request('convert', [
new Value(null, 'string'),
new Value($fileBase64, 'base64'),
new Value(null, 'null'),
new Value('pdf', 'string'),
new Value(null, 'null'),
new Value([], 'array'),
new Value(true, 'boolean'),
new Value(null, 'null'),
]);
$response = $client->send($req);
if (!$response->faultCode()) {
file_put_contents($outputFileName, $response->val->scalarVal());
} I wrote this code, and I get a pdf as output, but it has a base64 string :) The truth is somewhere nearby, perhaps Python uses the rb mode to read the file, but PHP doesn't. |
https://github.com/lynxtaa/unoserver-web Here's the thing I found, it looks like it's what I need, well at least for the time being, until I figure out how to do it myself. |
Well, that starts a webserver that will call the unoconvert client in a subprocess, which I assume you can do from PHP as well? So it's one step more than necessary. But if it works for you, sure. |
Maybe someone knows, as far as I understand unoconvert via REST accesses the unoserver and converts the document to PDF. Is it possible to convert a document via CURL without using unoconvert?
I am developing a REST application and would like to directly access unoserver.
The text was updated successfully, but these errors were encountered: