Can't Upload files - 400 Bad Request error

Hello, I just set up NextCloudPi on my Raspberry Pi 4.
I am able to add folders and add text documents to my NextCloud but when I try to upload an image or something similar I get error 400 Bad Request that the expected filesize does not match the witten filesize. I get the same issue from the browser, my Android phone and the Windows desktop program.

NextCloud version: 18.0.6.0
NextCloudPi version: v1.26.2
Rasbian OS version: 4.19.118-v7l+

Error Log when I upload

{ “reqId”:“XuvcW3OTWHPwzuC-uMzISAAAABE”,“level”:3,“time”:“2020-06-18T21:27:55+00:00”,“remoteAddr”:“my.ip.adress”,“user”:“user”,“app”:“PHP”,“method”:“PUT”,“url”:“/remote.php/dav/files/user/Test/nextcloud.jpg”,“message”:“fread(): file created in the system’s temporary directory at /var/www/nextcloud/3rdparty/icewind/streams/src/Wrapper.php#91”,“userAgent”:“Mozilla/5.0 (Windows) mirall/2.6.4stable-Win64 (build 20200303) (Nextcloud)”,“version”:“18.0.6.0”}

{“reqId”:“XuvcW3OTWHPwzuC-uMzISAAAABE”,“level”:3,“time”:“2020-06-18T21:27:55+00:00”,“remoteAddr”:“my.ip.adress”,“user”:“user”,“app”:“PHP”,“method”:“PUT”,“url”:“/remote.php/dav/files/user/Test/nextcloud.jpg”,“message”:“fread(): Unable to create temporary file, Check permissions in temporary files directory. at /var/www/nextcloud/3rdparty/icewind/streams/src/Wrapper.php#91”,“userAgent”:“Mozilla/5.0 (Windows) mirall/2.6.4stable-Win64 (build 20200303) (Nextcloud)”,“version”:“18.0.6.0”}

{“reqId”:“XuvcW3OTWHPwzuC-uMzISAAAABE”,“level”:3,“time”:“2020-06-18T21:27:55+00:00”,“remoteAddr”:“my.ip.adress”,“user”:“user”,“app”:“no app in context”,“method”:“PUT”,“url”:“/remote.php/dav/files/user/Test/nextcloud.jpg”,“message”:{“Exception”:“Sabre\DAV\Exception\BadRequest”,“Message”:“Expected filesize of 172325 bytes but read (from Nextcloud client) and wrote (to Nextcloud storage) 8192 bytes. Could either be a network problem on the sending side or a problem writing to the storage on the server side.”,“Code”:0,“Trace”:[{“file”:“/var/www/nextcloud/apps/dav/lib/Connector/Sabre/Directory.php”,“line”:156,“function”:“put”,“class”:“OCA\DAV\Connector\Sabre\File”,“type”:“->”,“args”:[null]},{“file”:“/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php”,“line”:1096,“function”:“createFile”,“class”:“OCA\DAV\Connector\Sabre\Directory”,“type”:“->”,“args”:[“nextcloud.jpg”,null]},{“file”:“/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php”,“line”:525,“function”:“createFile”,“class”:“Sabre\DAV\Server”,“type”:“->”,“args”:[“files/user/Test/nextcloud.jpg”,null,null]},{“function”:“httpPut”,“class”:“Sabre\DAV\CorePlugin”,“type”:“->”,“args”:[{“absoluteUrl”:“https://myipadress.com/remote.php/dav/files/user/Test/nextcloud.jpg",“__class__”:“Sabre\\HTTP\\Request”},{“__class__”:“Sabre\\HTTP\\Response”}]},{“file”:“/var/www/nextcloud/3rdparty/sabre/event/lib/EventEmitterTrait.php”,“line”:105,“function”:“call_user_func_array”,“args”:[[{“__class__”:“Sabre\\DAV\\CorePlugin”},“httpPut”],[{“absoluteUrl”:“https://myipadress.com/remote.php/dav/files/user/Test/nextcloud.jpg”,“__class__”:“Sabre\\HTTP\\Request”},{“__class__”:“Sabre\\HTTP\\Response”}]]},{“file”:“/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php”,“line”:479,“function”:“emit”,“class”:“Sabre\\Event\\EventEmitter”,“type”:"->”,“args”:[“method:PUT”,[{“absoluteUrl”:“https://myipadress.com/remote.php/dav/files/user/Test/nextcloud.jpg",“__class__”:“Sabre\\HTTP\\Request”},{“__class__”:“Sabre\\HTTP\\Response”}]]},{“file”:“/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php”,“line”:254,“function”:“invokeMethod”,“class”:“Sabre\\DAV\\Server”,“type”:"->”,“args”:[{“absoluteUrl”:“https://myipadress.com/remote.php/dav/files/user/Test/nextcloud.jpg",“__class__”:“Sabre\\HTTP\\Request”},{“__class__”:“Sabre\\HTTP\\Response”}]},{“file”:“/var/www/nextcloud/apps/dav/lib/Server.php”,“line”:319,“runction”:“exec”,“class”:“Sabre\\DAV\\Server”,“type”:"->”,“args”:},{“file”:“/var/www/nextcloud/apps/dav/appinfo/v2/remote.php”,“line”:35,“function”:“exec”,“class”:“OCA\DAV\Server”,“type”:“->”,“args”:},{“file”:“/var/www/nextcloud/remote.php”,“line”:165,“args”:[“/var/www/nextcloud/apps/dav/appinfo/v2/remote.php”],“function”:“require_once”}],“File”:“/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php”,“Line”:229,“CustomMessage”:“–”},“userAgent”:“Mozilla/5.0 (Windows) mirall/2.6.4stable-Win64 (build 20200303) (Nextcloud)”,“version”:“18.0.6.0”}

{“reqId”:“XuvcW3OTWHPwzuC-uMzISAAAABE”,“level”:4,“time”:“2020-06-18T21:27:55+00:00”,“remoteAddr”:“82.197.243.112”,“user”:“user”,“app”:“webdav”,“method”:“PUT”,“url”:“/remote.php/dav/files/user/Test/nextcloud.jpg”,“message”:{“Exception”:“Sabre\DAV\Exception\BadRequest”,“Message”:“Expected filesize of 172325 bytes but read (from Nextcloud client) and wrote (to Nextcloud storage) 8192 bytes. Could either be a network problem on the sending side or a problem writing to the storage on the server side.”,“Code”:0,“Trace”:[{“file”:“/var/www/nextcloud/apps/dav/lib/Connector/Sabre/Directory.php”,“line”:156,“function”:“put”,“class”:“OCA\DAV\Connector\Sabre\File”,“type”:“->”,“args”:[null]},{“file”:“/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php”,“line”:1096,“function”:“createFile”,“class”:“OCA\DAV\Connector\Sabre\Directory”,“type”:“->”,“args”:[“nextcloud.jpg”,null]},{“file”:“/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php”,“line”:525,“function”:“createFile”,“class”:“Sabre\DAV\Server”,“type”:“->”,“args”:[“files/user/Test/nextcloud.jpg”,null,null]},{“function”:“httpPut”,“class”:“Sabre\DAV\CorePlugin”,“type”:“->”,“args”:[{“absoluteUrl”:“https://myipadress.com/remote.php/dav/files/user/Test/nextcloud.jpg",“__class__”:“Sabre\\HTTP\\Request”},{“__class__”:“Sabre\\HTTP\\Response”}]},{“file”:“/var/www/nextcloud/3rdparty/sabre/event/lib/EventEmitterTrait.php”,“line”:105,“function”:“call_user_func_array”,“args”:[[{“__class__”:“Sabre\\DAV\\CorePlugin”},“httpPut”],[{“absoluteUrl”:“https://myipadress.com/remote.php/dav/files/user/Test/nextcloud.jpg”,“__class__”:“Sabre\\HTTP\\Request”},{“__class__”:“Sabre\\HTTP\\Response”}]]},{“file”:“/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php”,“line”:479,“function”:“emit”,“class”:“Sabre\\Event\\EventEmitter”,“type”:"->”,“args”:[“method:PUT”,[{“absoluteUrl”:“https://myipadress.com/remote.php/dav/files/user/Test/nextcloud.jpg",“__class__”:“Sabre\\HTTP\\Request”},{“__class__”:“Sabre\\HTTP\\Response”}]]},{“file”:“/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php”,“line”:254,“function”:“invokeMethod”,“class”:“Sabre\\DAV\\Server”,“type”:"->”,“args”:[{“absoluteUrl”:“https://myipadress.com/remote.php/dav/files/user/Test/nextcloud.jpg",“__class__”:“Sabre\\HTTP\\Request”},{“__class__”:“Sabre\\HTTP\\Response”}]},{“file”:“/var/www/nextcloud/apps/dav/lib/Server.php”,“line”:319,“function”:“exec”,“class”:“Sabre\\DAV\\Server”,“type”:"->”,“args”:},{“file”:“/var/www/nextcloud/apps/dav/appinfo/v2/remote.php”,“line”:35,“function”:“exec”,“class”:“OCA\DAV\Server”,“type”:“->”,“args”:},{“file”:“/var/www/nextcloud/remote.php”,“line”:165,“args”:[“/var/www/nextcloud/apps/dav/appinfo/v2/remote.php”],“function”:“require_once”}],“File”:“/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php”,“Line”:229,“CustomMessage”:“–”},“userAgent”:“Mozilla/5.0 (Windows) mirall/2.6.4stable-Win64 (build 20200303) (Nextcloud)”,“version”:“18.0.6.0”}

NextCloud config.php
<?php
$CONFIG = array (
  'passwordsalt' => 'MYPASSWORD',
  'secret' => 'MYPASSWORD',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    11 => '77.105.252.11',
    1 => '192.168.1.100',
    20 => 'myipadress.com',
    22 => '192.168.1.100',
    12 => 'myipadress.com',
  ),
  'datadirectory' => '/media/USBdrive/ncdata',
  'dbtype' => 'mysql',
  'version' => '18.0.6.0',
  'overwrite.cli.url' => 'https://myipadress.com/',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'ncadmin',
  'dbpassword' => 'MYPASSWORD',
  'installed' => true,
  'instanceid' => 'ocrl4v0pgt7h',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0.0,
    'password' => 'MYPASSWORD',
  ),
  'tempdirectory' => '/var/tmp/nc-tmp',
  'mail_smtpmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'preview_max_x' => '2048',
  'preview_max_y' => '2048',
  'jpeg_quality' => '60',
  'overwriteprotocol' => 'https',
  'maintenance' => false,
  'logfile' => '/var/log/nextcloud.log',
  'loglevel' => '2',
  'log_type' => 'file',
  'mail_sendmailmode' => 'smtp',
  'mail_smtpauth' => 1,
  'mail_smtpname' => 'nas@myhost.server',
  'mail_smtppassword' => 'mypassword',
  'mail_smtpsecure' => 'tls',
  'mail_from_address' => 'nas',
  'mail_domain' => 'myhost.server',
  'mail_smtphost' => 'smtp.myhost.server',
  'mail_smtpport' => '587',
  'default_language' => 'sv',
  'default_locale' => 'sv',
  'session_keepalive' => true,
  'session_lifetime' => 1800,
  'trashbin_retention_obligation' => 'auto',
  'appstoreenabled' => true,
  'theme' => '',
);

I have a SD card where NextCloud are installed, and then I have a HDD drive where I store all data. But I store tmp and log files in their own directories.

As you changed the default path.

Might check value of sys_temp_dir
in
/etc/php/7.3/fpm/php.ini

1 Like

That did the trick now it works as intended thank you :smiley:

Thanks. This solved the issue for me too.

For other people with this problem, please check which php.ini file to edit using phpinfo() (more info). In my case it was /etc/php/7.2/apache2/php.ini.

php -r "phpinfo();" would work from the command line on the system too.

2 Likes