fabi_s
February 25, 2019, 11:41am
1
Hello!
I want to send a POST request with curl from inside a filesystem hook.
$callback = function ($node) {
$file = curl_file_create(`, $node->getMimeType())
};
$this->fileManager->listen('\OC\Files', 'postCreate', $callback);
With $node->getPath()
and $node->getInternalPath()
no curl file is created.
Is it possible to get the $node
file from inside the hook, so i can add it to the body of the curl POST request?
Thanks and regards
Fabian
Filesystem hooks are already supply \OCP\Files\Node $node
. You can use it inside hook callback.
https://doc.owncloud.org/server/10.0/developer_manual/app/fundamentals/hooks.html
1 Like
fabi_s
March 1, 2019, 1:51pm
3
When i do this
$requestBody = array(
'model' => $dataJson,
'file' => $node
);
i get the following error message:
Object of class OC\\Files\\Node\\File could not be converted to string at \/var\/www\/owncloud\/apps\/owncloud-intrafind-connector\/lib\/Hooks\/FileSystem.php#127
When i do
$requestBody = array(
'model' => $dataJson,
'file' => curl_file_create($node, $mimeType)
);
i get the following message
curl_file_create() expects parameter 1 to be a valid path, object given at \/var\/www\/owncloud\/apps\/owncloud-intrafind-connector\/lib\/Hooks\/FileSystem.php#115
I think, what i need, is a function or something else that gives me the path to the data directory that is defined in the config.php.
fabi_s
March 1, 2019, 2:40pm
4
My solution now looks like this:
$dataDir = \OC::$server->getSystemConfig()->getValue('datadirectory');
$completePathToFile = $dataDir . $path;
$curlFile = curl_file_create($completePathToFile, $mimeType, $name);
$requestBody = array(
'model' => $dataJson,
'file' => $curlFile
);
Because like the message said, It is a node object, not a string. See this documentation. You can access much more thing about the node as well as its path: https://doc.owncloud.org/phpdoc/classes/OCP.Files.Node.html
1 Like