There’s a section in the SDK named modifying discovery.xml, but the section only talks about what the URL means and nothing about modifications, so is it possible to customize the URLs? For example, let different file types and actions use different URLs.
What you could do is restrict actions on file types, ie. edit → view_comment / view (though I’d say it’s more logical to do that on the integration side, as also the list of file types CODE/Collabora Online can open doesn’t necessarily mean you’d want to allow opening all those files).
Customizing the URLs isn’t an option.
I am using the PHP language to loading my collabora in iframe
and its working and loading the collabora i have set the wopi.php file to load document from any randome diractories extracting its content and showing in collabora editor. Once i loaded the content now i want to save my updates OR updated content on my original file so that i can overwrite my file.
Hi Paul - I’m struggling to connect your question to this thread about discovery.xml =) Please create a new topic if you have a question rather than appending it to many other existing threads.
To implement Save you need to support the POST end-point mentioned in the SDK something like this: collabora-online-sdk-examples/webapp/php/wopi/endpoints.php at master · CollaboraOnline/collabora-online-sdk-examples · GitHub
This is my wopi.php code where i am sending content to collabora
<?php
// $fileId = $_GET[''];
function generateAccessToken($fileId) {
return hash('sha256', $fileId);
}
// Parses the request
$uri = $_SERVER['REQUEST_URI'];
if (preg_match('/\/files\/(.+?)(\/contents)?\?/', $uri, $matches)) {
// Path to your documents directory
$file_root = $_GET['root_folder']; //'templates/2024-03';
$file_ext = $_GET['file_ext']; //'docx';
$can_edit = $_GET['can_edit']; //1;
$DOCUMENT_ROOT = '/var/www/html/demo/media/'.$file_root.'/';
$fileId = $matches[1]; // Extract the file ID from the URL
$accessToken = $_GET['access_token'] ?? ''; // Get the access token from query parameters
if($can_edit==1){
$edit=true;
}else{
$edit=false;
}
// Validate the access token
// echo $accessToken.'<br>';
// echo generateAccessToken($fileId);
// die();
if ($accessToken !== generateAccessToken($fileId)) {
header('HTTP/1.1 401 Unauthorized');
exit;
}
// Check if this is a file content request
if (isset($matches[2]) && $matches[2] === '/contents') {
// Serve the file content
$filePath = $DOCUMENT_ROOT . basename($fileId.'.'.$file_ext); // Basic sanitation
if (file_exists($filePath)) {
header('Content-Type: application/octet-stream');
readfile($filePath);
} else {
header('HTTP/1.1 404 Not Found');
}
} else {
// Serve file information
$filePath = $DOCUMENT_ROOT . basename($fileId.'.'.$file_ext); // Basic sanitation
// echo $filePath;
// die();
if (file_exists($filePath)) {
// echo "inside";
// die();
$response = [
'BaseFileName' => basename($filePath),
'Size' => filesize($filePath),
'OwnerId' => 'haider@legai.tech',
'Version' => '1',
'UserCanWrite' => $edit
];
header('Content-Type: application/json');
header('X-COOL-WOPI-ExtendedData');
echo json_encode($response);
} else {
header('HTTP/1.1 404 Not Found');
}
}
} else {
header('HTTP/1.1 400 Bad Request');
}
Looks fine - so the ‘Save’ is done by coming back to your PHP end-point with a POST - I expect you need to have a new branch in there that will handle that - for a POST as well as a GET - cf. collabora-online-sdk-examples/webapp/php/wopi/endpoints.php at master · CollaboraOnline/collabora-online-sdk-examples · GitHub
Do i need to add switch statement OR when it will be triggered to PutFile OR just should i add this code in this file openly.
$fh = fopen('php://input', 'r');
$fileContent = '';
while ($line = fgets($fh)) {
$fileContent = $fileContent . $line;
}
fclose($fh);
// you can check the new file content on the apache error log file
error_log('INFO: ' . $fileContent);
Also please let me know can i overwrite my origonal file?
Sorry; debugging PHP development remotely like this is not trivial. It would be great to re-use our existing PHP sample that should “just work” and is pleasantly structured code =) If there is some reason why you’re not doing that (perhaps because it’s split into two modules or ?..) that would be good to know - we can write an improved sample of course but … Ultimately serving three different end points two GET - for CheckFileInfo and ‘content’ and one POST up-loading new content should be reasonably easy I hope.