How to save files into an USB pendrive?

Hi everybody !

I would like to try to save files directly into a pendrive connected to the computer.

I installed Nextcloud through CasaOS and in Nextcloud apps, I enabled the one about external storage.

The point is when I clicked to set it up, there’s a warning like I have no permission or no external storage configured.

How to do it then ?

If you want to use an external storage in Nextcloud, it needs to be accessible for the webserver user. For ubuntu/debian this is the often cited www-data user (other systems it can be users like httpd, http, www, …)

with sudo -u www-data ls -l /path/to/external you can check the permissions.

Thank you very much but it didn’t work.

Is there an alternative way via GUI on Debian?

Update: It worked going to the External storage in the Administration section of Nextcloud, instead of user section. Sorry.

But even if I write the correct path (in Configuration) where the USB pendrive is connected, still didn’t work.

I tried sudo -u www-data ls -l /path/to/external even on root terminal. Nothing. Permission denied.

What to do ?

you need to fix the permissions that the webserver user can access the data. Make sure that on casaOS it is www-data (many use Debian/Ubuntu or other derivates and for them it is www-data).

Did you mean here: /DATA/AppData/nextcloud/var/www/html/ ?
The html folder with www-data as owner ?

Because that html folder already have that and with the USB pendrive connected, they both already have permissions of write and read but still didn’t work.

Just the USB path changed with /media/devmon/… but I tried with that and with the user name but nothing.

I don’t know what the problem is.

That is the main storage. With some luck it is the right user, what user is it currently?

This path needs to be accessible for the webserver user. And it needs to be through the whole folder structure, if the parent folders are not allowed for the webserver user it can’t see inside. Normally if you use the sudo -u webserver-user ls -lisa /path/to/folder if you see the listing, all the permissions are ok.

There’s only one user which is the admin.

I don’t understand this, sorry. I tried to write that command but gave me errors like:
sudo: unkown user webserver-admin
sudo: error in initializing the audit plugin sudoers_audit

Is there any via GUI method for Linux Mint or Ubuntu ?

On Linux systems, there are more users (normally), e.g. the webserver runs with dedicated user permissions. With cat /etc/passwd, you can see all these users. If there is www-data is in this list, your webserver probably runs with this user’s permissions.

Ok, so in the computer, not in Nextcloud. Sorry.

In my computer with Linux Mint right now there’s one user only (from Users and groups app) which is a custom account (not desktop user, not administrator).

With the command: sudo /etc/passwd I saw the www-data:

www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin

Ok, then the path to your pendrive (supposing it is /media/devmon/…), the folder should be readable with:

sudo -u www-data ls -lisa /media/devmon/…

use the full path, if you don’t have permissions, then the folder itself or the parent folders are not readable by www-data. If you use a GUI and you add a drive, it is associated with the GUI user by default (probably).

Ok, after few things I did, I used that command: sudo -u www-data ls -lisa not from root

The result:

totale 24
       2  4 drwxrwxrwx  3 fabio    fabio     4096 mar  5 18:55 .
19529730  4 drwxrwx---+ 4 www-data www-data  4096 mar  5 18:56 ..
      11 16 drwxrwxrwx  2 root     root     16384 mar  5 18:55 lost+found

I tried again on Nextcloud connecting to the correct path… nothing :man_shrugging:

As admin you add external storage, type local? You define a name, then you select local, give the path and then specify the users who will be able to see the stroage?
If it does not work, you don’t get the green check at the left of the line in the GUI where you configured it? In this case, check the logfile for more information. The logfile is in your normal (not external) data folder with name nextcloud.log.

Yes I didn’t get the green check even if the path has been correctly inserted.

Yes, nextcloud.log is here: /DATA/AppData/nextcloud/var/www/html/data/ but there are many things written.

What to do with nextcloud.log ?

Just check the log entries that appear when you try to set up the external storage.

If there are many other issues, it might be worth trying to fix them first.

I tried one more time to create the USB external storage to Nextcloud, but watching on the log reader inside Nextcloud GUI (I used that because watching directly from nextcloud.log I didn’t understand), there is something like:
Generato da PDOException: SQLSTATE[HY000]: General error: 5 database is locked

Don’t know if it’s the right one.

Or maybe this one:

nextcloud | 192.168.1.8 - - [06/Mar/2024:11:18:48 +0000] “PUT /apps/files_external/globalstorages/37 HTTP/1.1” 200 1063 “-” “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36”

If it is linked to other activities (client etc.), not sure about that. Do you use redis cache for filelocking (you should, especially if you read this message very often in the logs)?

The code 200 is good, no error.

For the locking, you can try to reduce other processes (mainly other clients connected).

I tried more than one time installing Debian 12 and with another installation of Nextcloud in CasaOS, and from logging of Nextcloud that’s the only error now:

OC\DB\Exceptions\DbalException: An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: oc_user_status.user_id

  1. /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php - line 328:OC\DB\Exceptions\DbalException::wrap([ "Doctrine\ … "])
  2. /var/www/html/lib/public/AppFramework/Db/QBMapper.php - line 137:OC\DB\QueryBuilder\QueryBuilder->executeStatement()
  3. /var/www/html/apps/user_status/lib/Listener/UserLiveStatusListener.php - line 104:OCP\AppFramework\Db\QBMapper->insert([ "OCA\User … l])
  4. /var/www/html/lib/private/EventDispatcher/ServiceEventListener.php - line 86:OCA\UserStatus\Listener\UserLiveStatusListener->handle([ "OCP\User … "])
  5. /var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 251:OC\EventDispatcher\ServiceEventListener->__invoke([ "OCP\User … "], “OCP\User\ … t”, [ "Symfony\ … "])
  6. /var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 73:Symfony\Component\EventDispatcher\EventDispatcher->callListeners([ [ “Closure”]], “OCP\User\ … t”, [ "OCP\User … "])
  7. /var/www/html/lib/private/EventDispatcher/EventDispatcher.php - line 94:Symfony\Component\EventDispatcher\EventDispatcher->dispatch([ "OCP\User … "], “OCP\User\ … t”)
  8. /var/www/html/lib/private/EventDispatcher/EventDispatcher.php - line 106:OC\EventDispatcher\EventDispatcher->dispatch(“OCP\User\ … t”, [ "OCP\User … "])
  9. /var/www/html/apps/user_status/lib/Controller/HeartbeatController.php - line 91:OC\EventDispatcher\EventDispatcher->dispatchTyped([ "OCP\User … "])
  10. /var/www/html/lib/private/AppFramework/Http/Dispatcher.php - line 230:OCA\UserStatus\Controller\HeartbeatController->heartbeat(“online”)
  11. /var/www/html/lib/private/AppFramework/Http/Dispatcher.php - line 137:OC\AppFramework\Http\Dispatcher->executeController([ "OCA\User … "], “heartbeat”)
  12. /var/www/html/lib/private/AppFramework/App.php - line 183:OC\AppFramework\Http\Dispatcher->dispatch([ "OCA\User … "], “heartbeat”)
  13. /var/www/html/lib/private/Route/Router.php - line 315:OC\AppFramework\App::main(“OCA\UserSt … r”, “heartbeat”, [ "OC\AppFr … "], [ "ocs.user_ … "])
  14. /var/www/html/ocs/v1.php - line 64:OC\Route\Router->match(“/ocsapp/app … t”)
  15. /var/www/html/ocs/v2.php - line 23:require_once(“/var/www/html/ocs/v1.php”)

Generato da Doctrine\DBAL\Exception\UniqueConstraintViolationException: An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: oc_user_status.user_id

  1. /var/www/html/3rdparty/doctrine/dbal/src/Connection.php - line 1814:Doctrine\DBAL\Driver\API\SQLite\ExceptionConverter->convert([ "Doctrine\ … "], [ “Doctrine\DBAL\Query”])
  2. /var/www/html/3rdparty/doctrine/dbal/src/Connection.php - line 1749:Doctrine\DBAL\Connection->handleDriverException([ "Doctrine\ … "], [ “Doctrine\DBAL\Query”])
  3. /var/www/html/3rdparty/doctrine/dbal/src/Connection.php - line 1163:Doctrine\DBAL\Connection->convertExceptionDuringQuery([ "Doctrine\ … "], “INSERT INTO … )”, [ “admin”,"o … e], [ 2,2,1,5])
  4. /var/www/html/lib/private/DB/Connection.php - line 295:Doctrine\DBAL\Connection->executeStatement(“INSERT INTO … )”, [ “admin”,"o … e], [ 2,2,1,5])
  5. /var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php - line 354:OC\DB\Connection->executeStatement(“INSERT INTO … )”, [ “admin”,"o … e], [ 2,2,1,5])
  6. /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php - line 280:Doctrine\DBAL\Query\QueryBuilder->execute()
  7. /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php - line 326:OC\DB\QueryBuilder\QueryBuilder->execute()
  8. /var/www/html/lib/public/AppFramework/Db/QBMapper.php - line 137:OC\DB\QueryBuilder\QueryBuilder->executeStatement()
  9. /var/www/html/apps/user_status/lib/Listener/UserLiveStatusListener.php - line 104:OCP\AppFramework\Db\QBMapper->insert([ "OCA\User … l])
  10. /var/www/html/lib/private/EventDispatcher/ServiceEventListener.php - line 86:OCA\UserStatus\Listener\UserLiveStatusListener->handle([ "OCP\User … "])
  11. /var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 251:OC\EventDispatcher\ServiceEventListener->__invoke([ "OCP\User … "], “OCP\User\ … t”, [ "Symfony\ … "])
  12. /var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 73:Symfony\Component\EventDispatcher\EventDispatcher->callListeners([ [ “Closure”]], “OCP\User\ … t”, [ "OCP\User … "])
  13. /var/www/html/lib/private/EventDispatcher/EventDispatcher.php - line 94:Symfony\Component\EventDispatcher\EventDispatcher->dispatch([ "OCP\User … "], “OCP\User\ … t”)
  14. /var/www/html/lib/private/EventDispatcher/EventDispatcher.php - line 106:OC\EventDispatcher\EventDispatcher->dispatch(“OCP\User\ … t”, [ "OCP\User … "])
  15. /var/www/html/apps/user_status/lib/Controller/HeartbeatController.php - line 91:OC\EventDispatcher\EventDispatcher->dispatchTyped([ "OCP\User … "])
  16. /var/www/html/lib/private/AppFramework/Http/Dispatcher.php - line 230:OCA\UserStatus\Controller\HeartbeatController->heartbeat(“online”)
  17. /var/www/html/lib/private/AppFramework/Http/Dispatcher.php - line 137:OC\AppFramework\Http\Dispatcher->executeController([ "OCA\User … "], “heartbeat”)
  18. /var/www/html/lib/private/AppFramework/App.php - line 183:OC\AppFramework\Http\Dispatcher->dispatch([ "OCA\User … "], “heartbeat”)
  19. /var/www/html/lib/private/Route/Router.php - line 315:OC\AppFramework\App::main(“OCA\UserSt … r”, “heartbeat”, [ "OC\AppFr … "], [ "ocs.user_ … "])
  20. /var/www/html/ocs/v1.php - line 64:OC\Route\Router->match(“/ocsapp/app … t”)
  21. /var/www/html/ocs/v2.php - line 23:require_once(“/var/www/html/ocs/v1.php”)

Generato da Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: oc_user_status.user_id

  1. /var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php - line 103:Doctrine\DBAL\Driver\PDO\Exception::new([ "PDOExcept … ]])
  2. /var/www/html/3rdparty/doctrine/dbal/src/Connection.php - line 1153:Doctrine\DBAL\Driver\PDO\Statement->execute()
  3. /var/www/html/lib/private/DB/Connection.php - line 295:Doctrine\DBAL\Connection->executeStatement(“INSERT INTO … )”, [ “admin”,"o … e], [ 2,2,1,5])
  4. /var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php - line 354:OC\DB\Connection->executeStatement(“INSERT INTO … )”, [ “admin”,"o … e], [ 2,2,1,5])
  5. /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php - line 280:Doctrine\DBAL\Query\QueryBuilder->execute()
  6. /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php - line 326:OC\DB\QueryBuilder\QueryBuilder->execute()
  7. /var/www/html/lib/public/AppFramework/Db/QBMapper.php - line 137:OC\DB\QueryBuilder\QueryBuilder->executeStatement()
  8. /var/www/html/apps/user_status/lib/Listener/UserLiveStatusListener.php - line 104:OCP\AppFramework\Db\QBMapper->insert([ "OCA\User … l])
  9. /var/www/html/lib/private/EventDispatcher/ServiceEventListener.php - line 86:OCA\UserStatus\Listener\UserLiveStatusListener->handle([ "OCP\User … "])
  10. /var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 251:OC\EventDispatcher\ServiceEventListener->__invoke([ "OCP\User … "], “OCP\User\ … t”, [ "Symfony\ … "])
  11. /var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 73:Symfony\Component\EventDispatcher\EventDispatcher->callListeners([ [ “Closure”]], “OCP\User\ … t”, [ "OCP\User … "])
  12. /var/www/html/lib/private/EventDispatcher/EventDispatcher.php - line 94:Symfony\Component\EventDispatcher\EventDispatcher->dispatch([ "OCP\User … "], “OCP\User\ … t”)
  13. /var/www/html/lib/private/EventDispatcher/EventDispatcher.php - line 106:OC\EventDispatcher\EventDispatcher->dispatch(“OCP\User\ … t”, [ "OCP\User … "])
  14. /var/www/html/apps/user_status/lib/Controller/HeartbeatController.php - line 91:OC\EventDispatcher\EventDispatcher->dispatchTyped([ "OCP\User … "])
  15. /var/www/html/lib/private/AppFramework/Http/Dispatcher.php - line 230:OCA\UserStatus\Controller\HeartbeatController->heartbeat(“online”)
  16. /var/www/html/lib/private/AppFramework/Http/Dispatcher.php - line 137:OC\AppFramework\Http\Dispatcher->executeController([ "OCA\User … "], “heartbeat”)
  17. /var/www/html/lib/private/AppFramework/App.php - line 183:OC\AppFramework\Http\Dispatcher->dispatch([ "OCA\User … "], “heartbeat”)
  18. /var/www/html/lib/private/Route/Router.php - line 315:OC\AppFramework\App::main(“OCA\UserSt … r”, “heartbeat”, [ "OC\AppFr … "], [ "ocs.user_ … "])
  19. /var/www/html/ocs/v1.php - line 64:OC\Route\Router->match(“/ocsapp/app … t”)
  20. /var/www/html/ocs/v2.php - line 23:require_once(“/var/www/html/ocs/v1.php”)

Generato da PDOException: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: oc_user_status.user_id

  1. /var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php - line 101:PDOStatement->execute(null)
  2. /var/www/html/3rdparty/doctrine/dbal/src/Connection.php - line 1153:Doctrine\DBAL\Driver\PDO\Statement->execute()
  3. /var/www/html/lib/private/DB/Connection.php - line 295:Doctrine\DBAL\Connection->executeStatement(“INSERT INTO … )”, [ “admin”,"o … e], [ 2,2,1,5])
  4. /var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php - line 354:OC\DB\Connection->executeStatement(“INSERT INTO … )”, [ “admin”,"o … e], [ 2,2,1,5])
  5. /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php - line 280:Doctrine\DBAL\Query\QueryBuilder->execute()
  6. /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php - line 326:OC\DB\QueryBuilder\QueryBuilder->execute()
  7. /var/www/html/lib/public/AppFramework/Db/QBMapper.php - line 137:OC\DB\QueryBuilder\QueryBuilder->executeStatement()
  8. /var/www/html/apps/user_status/lib/Listener/UserLiveStatusListener.php - line 104:OCP\AppFramework\Db\QBMapper->insert([ "OCA\User … l])
  9. /var/www/html/lib/private/EventDispatcher/ServiceEventListener.php - line 86:OCA\UserStatus\Listener\UserLiveStatusListener->handle([ "OCP\User … "])
  10. /var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 251:OC\EventDispatcher\ServiceEventListener->__invoke([ "OCP\User … "], “OCP\User\ … t”, [ "Symfony\ … "])
  11. /var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 73:Symfony\Component\EventDispatcher\EventDispatcher->callListeners([ [ “Closure”]], “OCP\User\ … t”, [ "OCP\User … "])
  12. /var/www/html/lib/private/EventDispatcher/EventDispatcher.php - line 94:Symfony\Component\EventDispatcher\EventDispatcher->dispatch([ "OCP\User … "], “OCP\User\ … t”)
  13. /var/www/html/lib/private/EventDispatcher/EventDispatcher.php - line 106:OC\EventDispatcher\EventDispatcher->dispatch(“OCP\User\ … t”, [ "OCP\User … "])
  14. /var/www/html/apps/user_status/lib/Controller/HeartbeatController.php - line 91:OC\EventDispatcher\EventDispatcher->dispatchTyped([ "OCP\User … "])
  15. /var/www/html/lib/private/AppFramework/Http/Dispatcher.php - line 230:OCA\UserStatus\Controller\HeartbeatController->heartbeat(“online”)
  16. /var/www/html/lib/private/AppFramework/Http/Dispatcher.php - line 137:OC\AppFramework\Http\Dispatcher->executeController([ "OCA\User … "], “heartbeat”)
  17. /var/www/html/lib/private/AppFramework/App.php - line 183:OC\AppFramework\Http\Dispatcher->dispatch([ "OCA\User … "], “heartbeat”)
  18. /var/www/html/lib/private/Route/Router.php - line 315:OC\AppFramework\App::main(“OCA\UserSt … r”, “heartbeat”, [ "OC\AppFr … "], [ "ocs.user_ … "])
  19. /var/www/html/ocs/v1.php - line 64:OC\Route\Router->match(“/ocsapp/app … t”)
  20. /var/www/html/ocs/v2.php - line 23:require_once(“/var/www/html/ocs/v1.php”)

Obviously I set up the USB pendrive with www-data and permissions of writing and reading on all levels, but still nothing.

I really don’t know what the problem is.

How is the pen-drive formatted? - The factory-default is vfat.