Create a new external storage backend in my app

Hello. I am developing an app to nextcloud which is an integration to a Matrix.org chat server. I want to implement an external storage backend to access files in the chat server. I have tried to mimic the other backends, creating a file OCA\Files_External\Lib\Backend\MatrixOrg inside the files_external/lib/Lib/Backend folder and other OCA\Files_External\Lib\Storage\MatrixOrg inside the files_external/lib/Lib/Storage folder.

The file Backend\MatrixOrg:

`class MatrixOrg extends Backend {

use LegacyDependencyCheckPolyfill;

public function __construct(IL10N $l, Password $legacyAuth) {
	$this
		->setIdentifier('matrixorg')
		->addIdentifierAlias('\OC\Files\Storage\MatrixOrg') // legacy compat
		->setStorageClass('\OCA\Files_External\Lib\Storage\MatrixOrg')
		->setText($l->t('Matrix.org server'))
		->addParameters([
			//(new DefinitionParameter('host', $l->t('Matrix.org server URL'))),
			//(new DefinitionParameter('user', $l->t('Remote user'))),
			//(new DefinitionParameter('password', $l->t('Remote password'))),
		])
		->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
		->setLegacyAuthMechanism($legacyAuth)
	;
}

}`

Storage\MatrixOrg is just Stub.

I have some questions about that.

  1. I cannot select my new backend in the administration section of the plugin after creating these two files. The new backend is not visible. In the settings.php there is a variable $_[‘backends’] , but I didn’t find where it was set. How to make this backend visible?

  2. Is this a best practice to create a external storage in an app? I intended to copy these files to my app directory as soon as the new external storage appeared.

Thank you.

1 Like

I have found an ownlcloud app who creates a new type of storage, and with that I could solve my problem.

https://apps.owncloud.com/content/show.php/files_hubic?content=168188

In app.php

$l = \OC::$server->getL10N('files_hubic');

OC::$CLASSPATH['OC\Files\Storage\Hubic'] = 'files_hubic/lib/hubic.php';

    \OCA\Files\App::getNavigationManager()->add([
   "id" => 'hubicstoragemounts',
   "appname" => 'files_hubic',
   "script" => 'list.php',
   "order" => 30,
   "name" => $l->t('Hubic External storage')
]);

OC_Mount_Config::registerBackend('\OC\Files\Storage\Hubic', [
   'backend' => (string)$l->t('Hubic'),
   'priority' => 100,
   'configuration' => [
      'configured' => '#configured',
      'client_id' => (string)$l->t('Client ID'),
      'client_secret' => '&*'.$l->t('Client secret'),
      'hubic_token' => '#hubic token',
      'swift_token' => '#swift token'
   ],
   'custom' => '../../files_hubic/js/hubic',
   'has_dependencies' => true,
   ]);

If did not works as expected, as this code is mostly deprecated.

@icewind Can you help here?

Hi Viniciuscb,

do you have any progress with your development? Maybe you can share your experience?

Any updated on this? A matrix (synapse home server) integration for users and files would be pretty awesome.

I have the riot.im web-client already running as an external page and it works great, but if the users accounts could also be syncronized… (there seems to be an under development LDAP auth for synapse, but I guess a direct link to the nextcloud user API would be much nicer for most admins).

By the way, check out these awesome new widget feature in riot.im:
https://medium.com/@RiotChat/riot-im-web-0-12-7c4ea84b180a
especially the Jitsi-meet video conferencing plugin is neat :wink: