Edit a document
edit
GET https://collaboractor.com/api/v1/edit/file?login=&password=&lang=
file is the name of the file in your personal space to edit.
login | Your identification code. |
---|---|
password | Your password. |
lang | Language of the interface of the editor. |
lang
- language of the editor, a code of 2 small letters, e.g. en
or fr
.
$ curl -X GET "https://collaboractor.com/api/v1/edit/file_sample_500kB.doc"?login=abcdef&password=ABCDEF&lang=en" > edit_sample_500kB.html
Display the HTML code of the document:
$ cat edit_sample_500kB.html
If the file name or the code of the language is invalid, the service returns the error HTTP/1.1 400 Bad Request
.
If no file has the specified name in your personal space, the service returns the error HTTP/1.1 404 Not Found
.
POST https://collaboractor.com/api/v1/edit?login=&password=&lang=
login | Your identification code. |
---|---|
password | Your password. |
lang | Language of the interface of the editor. |
multipart/form-data | |
file | Content of the document in binary. |
lang
- language of the editor, a code of 2 small letters, e.g. en
or fr
.
$ curl -X POST "https://collaboractor.com/api/v1/edit?login=abcdef&password=ABCDEF&lang=en" -F "file=@file_sample_500kB.doc;type=application/msword" > edit_sample_500kB.html
NOTE: Use a command such as file -ib file_sample_500kB.doc
to obtain the MIME type of the file passed with the argument file
.
Display the HTML code of the document:
$ cat edit_sample_500kB.html
If the file name or the code of the language is invalid or if the type of the file isn't supported or if the size of the file is greater than the maximum size of a file in your personal space, the service returns the error HTTP/1.1 400 Bad Request
.
if the number of files in your personal space has reached the authorized limit, the service returns the error HTTP/1.1 403 Forbidden
.
If a file with the same name already exists in your personal space, the service returns the error HTTP/1.1 409 Conflict
.
Download the code of the sendget
function from the iZend library.
Copy the file in the space of your application.
NOTE: See the page Call the service API for a description of the sendget
function.
Add the file fileedit.php with the following content:
- require_once 'sendhttp.php';
Loads the code of the sendpost
function.
- function file_edit($login, $password, $filename, $lang='en') {
Defines the function file_edit
.
$login
is your identification code. $password
is your password.
$filename
is the name of the file to edit.
$lang
specifies in which language the editor is to be displayed.
- $curl = 'https://collaboractor.com/api/v1/edit/' . urlencode($filename);
Sets $curl
to the URL of the edit action with the name of the file to edit.
- $args = array(
- 'login' => $login,
- 'password' => $password,
- 'lang' => $lang,
- );
Prepares the list of arguments of the GET: the identification code and the password of the user's account, the language of the editor.
- $response=sendget($curl, $args);
Sends the HTTP request with sendget
.
- if (!$response or $response[0] != 200) {
- return false;
- }
If $response
is false
, the server is unreachable.
If $response[0]
doesn't contain the HTTP return code 200 Ok, an execution error has occurred.
In case of error, file_edit
returns false.
- return $response[2];
- }
Returns a complete HTML document containing a form which is automatically sent to the service which returns the editor which is displayed full page in a <iframe>
.
EXAMPLE
The HTML document with the editor returned by the service can be obtained by the server of an another website, preferably after an interaction from a user, and sent back to the navigator by a simple action in response to a GET which can check if the user is identified, send a request to the service with the login and password for the user, the name of the file to edit, check the response from the service and return the HTML document which will embed the editor in a <iframe>
which the navigator can display full page in a new window.
Adapt the following function to your development environment:
- require_once 'sendhttp.php';
- function collabora() {
- $login='abcdef';
- $password='ABCDEF';
- $file='file_example_PPT_250kB.ppt';
- $lang='en';
- $curl = 'https://collaboractor.com/api/v1/edit/' . urlencode($file);
- $args = array(
- 'login' => $login,
- 'password' => $password,
- 'lang' => $lang,
- );
- $response=sendget($curl, $args);
- if (!$response or $response[0] != 200) {
- header('HTTP/1.1 500 Internal Error');
- }
- else {
- header('HTTP/1.1 200 OK');
- header('Cache-Control: no-cache');
- echo $response[2];
- }
- }
NOTE: In a real implementation, the user's identification needs to be checked, the parameters $login
and $password
are read from the session or a database and the name of the file to edit can be retrieved from the URL.
To run the editor in your website, try a simple button which when clicked calls the function window.open
of the navigator with in argument the URL which responds to the GET with your implementation of the collabora
function with the name of the file to edit in the URL.
- <p><input type="submit" class="submit" id="btn_collabora_edit" value="Edit" /></p>
- <script>
- document.getElementById('btn_collabora_edit').onclick = () => window.open('/collabora/file_example_PPT_250kB.ppt');
- </script>
Comments