我已经在NextCloud中创建了一个应用程序,并且希望它在NextCloud中自动创建与具有不同权限的指定用户共享的文件夹。
我很难理解如何创建文件夹甚至文件。
据我了解,我必须使用其中描述的FileSystem:
这在文档中未指定,但是我放置了:
Application类为:
$products->each->append('pricing_by_id');
AuthorStorage类为:
<?php
namespace OCA\MyApp\AppInfo;
use \OCP\AppFramework\App;
use \OCA\MyApp\Storage\AuthorStorage;
class Application extends App {
public function __construct(array $urlParams=array()){
parent::__construct('myapp', $urlParams);
$container = $this->getContainer();
/**
* Storage Layer
*/
$container->registerService('AuthorStorage', function($c) {
return new AuthorStorage($c->query('RootStorage'));
});
$container->registerService('RootStorage', function($c) {
return $c->query('ServerContainer')->getRootFolder();
});
}
}
在我的一个控制器中,我致电:
<?php
namespace OCA\MyApp\Storage;
class AuthorStorage {
private $storage;
public function __construct($storage){
$this->storage = $storage;
}
public function writeTxt($content) {
// check if file exists and write to it if possible
try {
try {
$file = $this->storage->get('/myfile.txt');
} catch(\OCP\Files\NotFoundException $e) {
$this->storage->touch('/myfile.txt');
$file = $this->storage->get('/myfile.txt');
}
// the id can be accessed by $file->getId();
$file->putContent($content);
} catch(\OCP\Files\NotPermittedException $e) {
// you have to create this exception by yourself ;)
throw new StorageException('Cant write to file');
}
}
}
但是,这会触发$class2 = $app->getContainer()->query('OCA\MyApp\Storage\AuthorStorage');
$class2->writeTxt('test');
异常。我不确定是否完全掌握这里发生的事情。我的OCP\Files\NotPermittedException
文件夹是否存在权限问题(Linux数据所有者为data
,所以我认为不是)?它与我的nextcloud用户(管理员)的权限有关吗?我是否只是在尝试在错误的目录中写入?我需要在某个地方指定用户ID吗?
感谢您的帮助!