Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebDAV: Uploading to Nextcloud may result in 0 byte files #443

Closed
RAYs3T opened this issue Aug 4, 2020 · 49 comments
Closed

WebDAV: Uploading to Nextcloud may result in 0 byte files #443

RAYs3T opened this issue Aug 4, 2020 · 49 comments
Assignees
Labels
docs 📚 Write, improve, or review documentation enhancement Refactoring, improvement or maintenance task tested Changes have been tested successfully

Comments

@RAYs3T
Copy link
Contributor

RAYs3T commented Aug 4, 2020

Preamble

Im not sure if this is something broken with my nextcloud instance or actually a bug.
So i would appreciate if someone (who has access to a Nextcloud instance) could test this.

Problem desciption

If you setup the upload via WebDAV to nextcloud and share one or multiple pictures, the file in nextcloud is emtpy. It basically only created the file with no contents. Therefore you can't load/display the picture.

image

Also if you download the file it has zero bytes in it.

Logs

Log output from PhotoPrism:

photoprism_1  | time="2020-08-04T08:44:36Z" level=debug msg="GET /api/v1/accounts?share=true&count=1000&offset=0 (200) [2.157622ms]"
photoprism_1  | time="2020-08-04T08:44:36Z" level=debug msg="cache hit for account-folders:1 [80.977µs]"
photoprism_1  | time="2020-08-04T08:44:36Z" level=debug msg="GET /api/v1/accounts/1/folders (200) [191.263µs]"
photoprism_1  | time="2020-08-04T08:44:43Z" level=debug msg="GET /api/v1/status (200) [77.041µs]"
photoprism_1  | time="2020-08-04T08:44:43Z" level=debug msg="POST /api/v1/accounts/1/share (200) [32.591231ms]"
photoprism_1  | time="2020-08-04T08:44:54Z" level=info msg="share-worker: uploaded //20200803-201544-Unknown-2020-10f.jpg to Edging-Technology"

Log output from Nextcloud:

84.46.x.x - - [04/Aug/2020:10:44:44 +0200] "PUT /remote.php/dav/files/RAYs3T//20200803-201544-Unknown-2020-10f.jpg HTTP/1.1" 401 557
80.187.x.x - - [04/Aug/2020:10:44:50 +0200] "POST /apps/text/session/sync HTTP/1.1" 200 318
84.46.x.x - - [04/Aug/2020:10:44:49 +0200] "PUT /remote.php/dav/files/RAYs3T//20200803-201544-Unknown-2020-10f.jpg HTTP/1.1" 201 -
@uLUViL3gCs
Copy link

uLUViL3gCs commented Aug 6, 2020

So i would appreciate if someone (who has access to a Nextcloud instance) could test this.

I can confirm same behavior in my environment.

Steps I performed:

  • PP, Settings, Backup: Add NC server
  • PP, Photos: Select some random photos, Click "Share" button
  • NC: the amount and names of the selected photos is created
    => The file size remains 0 KB.

Screenshot 2020-08-06 at 17 27 17

Environment:
PhotoPrism™ 200724-2859549-Linux-x86_64
NC 19.0.1

PP logs:

time="2020-08-06T15:18:26Z" level=info msg="share-worker: uploaded /Photos/20200727-080557-Dog-2020-1fj.jpg to Cloud"

time="2020-08-06T15:18:26Z" level=info msg="share-worker: uploaded /Photos/20200101-172823-Berlin-Germany-2020-1r8.jpg to Cloud"

NC logs:

x.x.x.x - - [06/Aug/2020:17:18:25 +0200] "MKCOL /remote.php/webdav/Photos/ HTTP/2.0" 401 414 "-" "Go-http-client/2.0" "-"
x.x.x.x - pp [06/Aug/2020:17:18:25 +0200] "MKCOL /remote.php/webdav/Photos/ HTTP/2.0" 405 247 "-" "Go-http-client/2.0" "-"
x.x.x.x - pp [06/Aug/2020:17:18:25 +0200] "MKCOL /remote.php/webdav/Photos/ HTTP/2.0" 405 247 "-" "Go-http-client/2.0" "-"
x.x.x.x - pp [06/Aug/2020:17:18:26 +0200] "PUT /remote.php/webdav/Photos/20200727-080557-Dog-2020-1fj.jpg HTTP/2.0" 201 0 "-" "Go-http-client/2.0" "-"
x.x.x.x - pp [06/Aug/2020:17:18:26 +0200] "MKCOL /remote.php/webdav/Photos/ HTTP/2.0" 405 247 "-" "Go-http-client/2.0" "-"
x.x.x.x - pp [06/Aug/2020:17:18:26 +0200] "MKCOL /remote.php/webdav/Photos/ HTTP/2.0" 405 247 "-" "Go-http-client/2.0" "-"
x.x.x.x - pp [06/Aug/2020:17:18:26 +0200] "PUT /remote.php/webdav/Photos/20200101-172823-Berlin-Germany-2020-1r8.jpg HTTP/2.0" 201 0 "-" "Go-http-client/2.0" "-"

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Aug 11, 2020

@lastzero I guess this has to be considered a part of the MVP milestone?

@lastzero lastzero self-assigned this Aug 11, 2020
@lastzero lastzero added the bug Something isn't working label Aug 11, 2020
@lastzero lastzero added this to the MVP milestone Aug 11, 2020
@lastzero
Copy link
Member

Yes, going to look into that soon!

@lastzero
Copy link
Member

Couldn't find any issues when uploading to Nextcloud 19.0.1:

Screenshot 2020-08-12 at 06 32 00

Also doesn't matter how many files I select, they are properly uploaded. Note that we don't use https for our local test environment, this can make a difference (connection should fail completely though).

Logs:

2020-08-12 06:37:10 INFO share-worker: uploaded //20190609-125732-Travelex-Currency-Exchange-2019-25w.jpg to Neon
2020-08-12 06:37:10 INFO share-worker: uploaded //20150212-031100-Theme-Park-Santa-Monica-2015-17p.jpg to Neon

To debug this further, we need additional information. Maybe it's just a file permission problem, either in Nextcloud or PhotoPrism?

@lastzero lastzero added the waiting Impediment / blocked / waiting label Aug 12, 2020
@lastzero
Copy link
Member

Maybe this only affects certain file types or there is a request size limit in Nextcloud or a proxy in front of it?

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Aug 12, 2020

Test with a third-party WebDAV client works

Just to make sure this isn't caused by the Nextcloud I've used a third-party WebDAV client (Cyberduck) and tested the upload.
The upload succeeded and the file had the correct size (selected file was uploaded with the WebDAV client. others are from PP.

image

Proxy

The Nextcloud is hosted by the Apache, the this is serving the content directly without a additional proxy in front of it.

Directory listing works, upload itself not.

I don't think this has something to do with HTTPs. The listing of the upload directories works. You can see the folders that exists on the Nextcloud and select the correct one. I've also tried using the root directory and not a sub-folder. Same result.

File upload call gets rejected with 401, unauthorized.

In the last test I discovered someshow that the final call that should upload the file gets rejected with HTTP status 401, others work fine tho...

95.81.15.169 - - [12/Aug/2020:09:18:35 +0200] "PROPFIND /remote.php/dav/files/RAYs3T/ HTTP/1.1" 401 557
95.81.15.169 - - [12/Aug/2020:09:18:36 +0200] "PROPFIND /remote.php/dav/files/RAYs3T/ HTTP/1.1" 207 3880
95.81.15.169 - - [12/Aug/2020:09:18:36 +0200] "PROPFIND /remote.php/dav/files/RAYs3T/Auth/ HTTP/1.1" 207 2872
95.81.15.169 - - [12/Aug/2020:09:18:37 +0200] "PROPFIND /remote.php/dav/files/RAYs3T/MobileBackups/ HTTP/1.1" 207 1173
95.81.15.169 - - [12/Aug/2020:09:18:38 +0200] "PROPFIND /remote.php/dav/files/RAYs3T/PP-Shares/ HTTP/1.1" 207 3996
95.81.15.169 - - [12/Aug/2020:09:18:38 +0200] "PROPFIND /remote.php/dav/files/RAYs3T/ShareXUploads/ HTTP/1.1" 207 34136
...
95.81.15.169 - - [12/Aug/2020:09:18:46 +0200] "PUT /remote.php/dav/files/RAYs3T//20200811-201311-Otto-Von-Bahren-Park-Hamburg-2020-1y1.jpg HTTP/1.1" 401 557

... so the WebDAV implementation used in PP is not checking for the status of the file upload?
2020-08-12 09:19:03 INFO share-worker: uploaded //20200811-201311-Otto-Von-Bahren-Park-Hamburg-2020-1y1.jpg to Edging-Technology

Test with different file types

To rule out an error with the size or type I uploaded the same file that I've used in the upload with cyberduck, uploaded it to PP and tried to share it from there. Same result. 0KB

Used Nextcloud version: 18.0.7

@lastzero
Copy link
Member

Our WebDAV upload is based on https://github.com/studio-b12/gowebdav

They also have a stand-alone command you can use for testing: https://github.com/studio-b12/gowebdav/tree/master/cmd/gowebdav

@lastzero
Copy link
Member

lastzero commented Aug 12, 2020

Looks like there is a \ too much in the server path: /remote.php/dav/files/RAYs3T// ?

Edit: Think I can also see it in my logs, so not sure if this is something that needs a fix.

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Aug 12, 2020

Yep, that's an issue in the gowebdav client.
image

PS C:\development\test> $env:ROOT = "https://nc.edging-technology.net/remote.php/dav/files/RAYs3T/"
PS C:\development\test> $env:USER = "RAYs3T"
PS C:\development\test> $env:PASSWORD = "....."
PS C:\development\test> gowebdav -X PUT /webdav_test.png .\Chart_KAD.PNG
Put: .\Chart_KAD.PNG -> /webdav_test.png

image

I will test a little bit more and raise an issue over there. I wonder why it is working without issues for your tho...

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Aug 12, 2020

Opened an initial issue studio-b12/gowebdav#35

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Aug 12, 2020

@lastzero and I have the bad feeling that this might be our issue... studio-b12/gowebdav#28

@lastzero
Copy link
Member

Error reporting might be an issue, but what causes the error in the first place? Maybe just a small change needed as it works over here.

Are there custom settings for Nextcloud that can lead to auth issues? Plugins?

We use URL auto detection when adding the account (http://servername/). Manually entering the full WebDAV path may lead to a slightly different request URL.

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Aug 12, 2020

Hmm tried it with the short (autogen) and full path. Same result.
I found some issue over at Nextcloud, but it's a little bit different (for them the file in storage is ok, while in my environment also the file stored on the spinning rust is only the encryption header, nothing else...

nextcloud/server#21315

Is your storage encrypted?

Also I've upgrade my instance to 19.0.1, same issue persists.

@lastzero
Copy link
Member

No, we don't modify originals. So no encryption whatsoever. Maybe a HTTP / Webserver issue after all, or there's a problem with the base64 encoded password in the header (there are slightly different standards for this, do you use any special characters other than a-z and 0-9?).

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Aug 12, 2020

It's actually an app password generated by Nextcloud itself. Looks something like this P42LX-gd4kw-Lk4Ia-9331kLa-6z7hh

With the encryption I was referring to your test nextcloud instance Is the build-in nextcloud encryption enbaled for this?

@lastzero
Copy link
Member

lastzero commented Aug 12, 2020

Probably not... If this is not the default.

Maybe there's an issue with encryption and app passwords?

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Aug 12, 2020

Hmm ok because in the nextcloud issue there is some relation to encryption.. @uLUViL3gCs do you have encryption enabled in your instance?

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Aug 13, 2020

@lastzero could you try this with your build against https://try.nextcloud.com/ ? (User gets created automatically)
I was able to reproduce the same behavior there. So i can rule out issues with my instance.

I will dig around in the gowebdav later and see if i can figure out what is causing this. A quick look revealed that the status returned from the NC instance does not include any error so far, but I will dive deeper into it later.

@uLUViL3gCs
Copy link

@uLUViL3gCs do you have encryption enabled in your instance?

No, I am not using encryption as coming along, build-in by NC.

It's actually an app password generated by Nextcloud itself. Looks something like this P42LX-gd4kw-Lk4Ia-9331kLa-6z7hh

Same here.

I found some issue over at Nextcloud, but it's a little bit different (for them the file in storage is ok, while in my environment also the file stored on the spinning rust is only the encryption header, nothing else...

Just to let you know that even on storage the uploaded file size is 0kB in my case.

could you try this with your build against https://try.nextcloud.com/ ?

Using nextcloud demo and the same local PP, I am encountering same issue (files visible, file size == 0kB).

Just for your information that I am using nginx for the local PP instance.

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Aug 13, 2020

I'm also using nginx as revrese proxy. But it should not have any impact since the connection to Nextcloud is direct without a proxy (PP connects directly to the NC instance via HTTPS)

@lastzero
Copy link
Member

Did anyone try without app password? Do app passwords also have a username or is it just the password without username?

Nginx will limit upload size by default, we had many "bug" reports related to this when the real issue was that the files were larger than what nginx was configured for.

@lastzero
Copy link
Member

That reminds me that we run Nextcloud behind a Caddy proxy, so this might fix / modify the request in a certain way...

@lastzero
Copy link
Member

Could it be a locking issue? See https://help.nextcloud.com/t/file-is-locked-how-to-unlock/1883

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Aug 13, 2020

app password use the same username as the normal login.
I'll try it without an app password in the try.nextcloud.com instance...

@uLUViL3gCs
Copy link

Did anyone try without app password?

Yes, just now on my local NC => Same result, file gets uploaded, 0kB size.

Do app passwords also have a username or is it just the password without username?

Yes, same user name is required.

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Sep 1, 2020

Did move my instance to nginx. Same issue.
Uploaded file:
image

Nginx logs:

2a04:4540:6a25:5e50:8cb:a962:7a2:5ee4 - RAYs3T [01/Sep/2020:22:55:32 +0200] "PROPFIND /remote.php/dav/files/RAYs3T/ HTTP/1.1" 207 400 "-" "Mozilla/5.0 (Windows) mirall/3.0.0stable-Win64 (build 20200811) (Nextcloud)"
127.0.0.1 - - [01/Sep/2020:22:55:32 +0200] "GET /server-status?auto HTTP/1.1" 404 162 "-" "-"
2a04:4540:6a25:5e50:8cb:a962:7a2:5ee4 - - [01/Sep/2020:22:55:33 +0200] "GET /api/mmr/overview HTTP/2.0" 200 42 "https://playcheck.siege-insights.net/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0"
149.224.33.109 - - [01/Sep/2020:22:55:34 +0200] "PUT /remote.php/dav/files/RAYs3T//20200829-123114-Markmannsgasse-Cologne-2020-1l8.jpg HTTP/2.0" 401 557 "-" "Go-http-client/2.0"
149.224.33.109 - RAYs3T [01/Sep/2020:22:55:34 +0200] "PUT /remote.php/dav/files/RAYs3T//20200829-123114-Markmannsgasse-Cologne-2020-1l8.jpg HTTP/2.0" 201 0 "-" "Go-http-client/2.0""

PP logs:

time="2020-09-01T20:55:32Z" level=debug msg="GET /api/v1/accounts?share=true&count=1000&offset=0 (200) [859.533µs]"
time="2020-09-01T20:55:32Z" level=debug msg="cache hit for account-folders:3 [46.932µs]"
time="2020-09-01T20:55:32Z" level=debug msg="GET /api/v1/accounts/3/folders (200) [121.657µs]"
time="2020-09-01T20:55:34Z" level=debug msg="POST /api/v1/accounts/3/share (200) [14.576387ms]"
time="2020-09-01T20:55:34Z" level=info msg="share-worker: uploaded //20200829-123114-Markmannsgasse-Cologne-2020-1l8.jpg to Edging-Technology"

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Sep 1, 2020

Also tried it with the nginx option chunked_transfer_encoding on;, no difference :(

@lastzero
Copy link
Member

lastzero commented Sep 2, 2020

Did you follow the advice on https://trac.cyberduck.io/wiki/help/en/howto/mount/issues/fastcgi and https://sabre.io/dav/0bytes/?

Seems like fastcgi_request_buffering should be enabled as well.

@lastzero lastzero changed the title WebDAV picture upload to nextcloud seems to be broken WebDAV: Uploading to Nextcloud may result in 0 byte files Sep 2, 2020
@RAYs3T
Copy link
Contributor Author

RAYs3T commented Sep 2, 2020

Finally - This did the trick! You've to enable fastcgi_request_buffering = on and it works.

Keep in mind that the default nextcloud documentations states that you turn this off. So the majority of people will most likley have the same issue.

@lastzero
Copy link
Member

lastzero commented Sep 2, 2020

Excellent, so the only thing we need to do is add specific docs for Nextcloud users?

Edit: Maybe you should only enable it for WebDAV routes, not for regular Nextcloud pages. Might have a performance impact.

@RAYs3T
Copy link
Contributor Author

RAYs3T commented Sep 2, 2020

Yes. I guess this will be enough.
Kinda sad that it isn't working with apache on the other hand (maybe there is something similar you can configure..)

For me it's fine since I wanted to switch to Nginx anyways... :)

Setting the option only for the webdav routes is a good idea. Will change that in my configuration.

@uLUViL3gCs
Copy link

Finally - This did the trick! You've to enable fastcgi_request_buffering = on and it works.

Just to let you know that the same is true for my instance; changing
fastcgi_request_buffering off;
to
fastcgi_request_buffering on;
lets the photo being uploaded in full size:
Screenshot 2020-09-02 at 13 59 58

@lastzero lastzero added docs 📚 Write, improve, or review documentation enhancement Refactoring, improvement or maintenance task and removed bug Something isn't working please-test Ready for acceptance test waiting Impediment / blocked / waiting labels Sep 2, 2020
@deajan
Copy link

deajan commented Sep 4, 2020

Adding my grain of salt.
I experience same issues of 0 bytes files using the WebDAV implementation of a Canon ImageRunner Advanced printer/scanner (C5250 model).
I'm running PHP 7.4.10/Apache 2.4.36/NC 19.0.2, no reverse proxy.
I've tried to switch from php-fpm to mod_php (change the MPM event to prefork and check that php.conf file exists) so I can outrule any proxy related issues.

I can indeed upload via CURL using curl -X PUT -T ./test.pdf --user Scanner:myscannerpassword --header "Transfer-Encoding: chunked" https://cloud.mynextcloud.tld/remote.php/dav/files/Scanner/scan.pdf

Strange enough, I found a way to make my uploads work:
Using this path fails:
https://cloud.mynextcloud.tld/remote.php/dav/files/username/MYFOLDER

Using this path works:
https://cloud.mynextcloud.tld/remote.php/webdav/MYFOLDER

The latter still creates 0 byte size files in the GUI, but this time, the file is actually transfered, and exists with a real size in the data directory.
The 0 byte file in GUI only (when the file has a real size) is another problem seen here nextcloud/server#21315

Now the fun part is: If I happen to switch back to php-fpm to mod_php , the above solution doesn't work anymore.

Hope this helps someone until this gets sorted out.

@kesselb
Copy link

kesselb commented Sep 4, 2020

@deajan
Copy link

deajan commented Sep 4, 2020

@kesselb Does indeed explain the php-fpm problem that gets resolved by using mod_php ;)
Doesn't explain the problem depening on remote.php/dav/files/username vs remote.php/webdav problem, neither the 0 sized fiels in DB only.

What's the difference between dav and webdav URIs ?

@kesselb
Copy link

kesselb commented Sep 4, 2020

@deajan wrong repository as your problem/question is not related to photoprism ;)

@deajan
Copy link

deajan commented Sep 4, 2020

@kesselb Ahem... yes ;) Sorry for the noise

@deajan
Copy link

deajan commented Sep 15, 2020

FYI, here's the explanation and possible solutions https://trac.cyberduck.io/wiki/help/en/howto/mount/issues/fastcgi

@graciousgrey
Copy link
Member

As this is mentioned in our docs (https://docs.photoprism.org/user-guide/settings/sync/). Can we close this issue or is there something left todo? @lastzero

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs 📚 Write, improve, or review documentation enhancement Refactoring, improvement or maintenance task tested Changes have been tested successfully
Projects
Status: Release 🌈
Development

No branches or pull requests

7 participants
@lastzero @kesselb @deajan @graciousgrey @RAYs3T @uLUViL3gCs and others