AppData

Often an app wants to store data. However not all data that is stored belongs with the users files. Often you just want a very simple storage to have some temp files. In order to facilitate this there is the AppData folder that provides each app with a private simple filesystem.

Usage is almost trivial when your app is using the AppFramework.

  1. <?php
  2. namespace OCA\MyApp\Controller\MyController;
  3. use OCP\AppFramework\Controller;
  4. use OCP\Files\IAppData;
  5. use OCP\IRequest;
  6. class MyController extends Controller {
  7. /** @var IAppData */
  8. private $appData;
  9. public function __construct($appName,
  10. IRequest $request,
  11. IAppData $appData) {
  12. parent::__construct($appName, $request);
  13. $this->appData = $appData;
  14. }
  15. }

This gives your controller access to the IAppData simple filesystem of your app.

The simple filesystem

The IAppData uses the simple filesystem. This is a very simplified filesystem that will allow for easy mapping to for example memcaches. The filesystem has three elements: root, folder, file.

The root can only contain folders. And each folder can only contain files. This is limited to keep things simple and to allow easy mapping to other backends. For example a sysadmin might chose to map the avatars to fast storage since they are used often.

Root

The root element can only contain folders. There are 3 things you can do on a root element:

  • getFolder: get the folder you request
  • newFolder: creates a new folder
  • getDirectoryListing: lists all the folders in this root

Folder

A folder has a bit more options.

  • getDirectoryListing: lists all the files in the folder
  • fileExists: check if a file exists
  • getFile: get a file
  • newFile: create a new file
  • delete: delete a folder and its content
  • getName: get the name of the folder

File

  • getName: get the name of the file
  • getSize: get the size of the file
  • getETag: get the ETag of the file
  • getMTime: get the modification time of the file
  • getContent: get the content of the file
  • putContent: write content to the file
  • delete: delete the file
  • getMimeType: get the mimetype of the file
  • read: get a resource for reading the file
  • write: get a resoruce for writing to the file