13

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.

loginYour identification code.
passwordYour password.
langLanguage 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=

loginYour identification code.
passwordYour password.
langLanguage of the interface of the editor.
multipart/form-data
fileContent 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:

  1. require_once 'sendhttp.php';

Loads the code of the sendpost function.

  1. 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.

  1.     $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.

  1.     $args = array(
  2.         'login'     => $login,
  3.         'password'  => $password,
  4.         'lang'      => $lang,
  5.     );

Prepares the list of arguments of the GET: the identification code and the password of the user's account, the language of the editor.

  1.     $response=sendget($curl, $args);

Sends the HTTP request with sendget.

  1.     if (!$response or $response[0] != 200) {
  2.         return false;
  3.     }

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.

  1.     return $response[2];
  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:

  1. require_once 'sendhttp.php';
  2.  
  3. function collabora() {
  4.     $login='abcdef';
  5.     $password='ABCDEF';
  6.     $file='file_example_PPT_250kB.ppt';
  7.     $lang='en';
  8.  
  9.     $curl = 'https://collaboractor.com/api/v1/edit/' . urlencode($file);
  10.  
  11.     $args = array(
  12.         'login'     => $login,
  13.         'password'  => $password,
  14.         'lang'      => $lang,
  15.     );
  16.  
  17.     $response=sendget($curl, $args);
  18.  
  19.     if (!$response or $response[0] != 200) {
  20.         header('HTTP/1.1 500 Internal Error');
  21.     }
  22.     else {
  23.         header('HTTP/1.1 200 OK');
  24.         header('Cache-Control: no-cache');
  25.  
  26.         echo $response[2];
  27.     }
  28. }

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.

  1. <p><input type="submit" class="submit" id="btn_collabora_edit" value="Edit" /></p>
  2. <script>
  3. document.getElementById('btn_collabora_edit').onclick = () => window.open('/collabora/file_example_PPT_250kB.ppt');
  4. </script>
SEE ALSO

Call the service API, Upload a document

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].