provokateurin / dart-nextcloud

A Nextcloud client for dart
Other
20 stars 15 forks source link

If the file was copied to another folder, you can't get a preview of the image. #11

Closed ike20013 closed 4 years ago

ike20013 commented 4 years ago

Hello, I found this problem: If I copied the image to another folder, I can't get the preview via remotePath. As I understand it, nextcloud preview images are taken through the ID, not through the path, but you do not have the implementation of getting the ID. How can I fix this myself in my code, or you need to fix it on your side?

provokateurin commented 4 years ago

Can you provide a minimal example to demonstrate the problem?

ike20013 commented 4 years ago

In short, I made a copy of the image from one folder to another, using "copy", and because of this, getPreview and getThumbnail return an empty uint8list array, I also checked the link that your script generates, there I get [], an empty array, apparently this happens because nextcloud itself takes a preview of the image by the file ID, and not by its remote path, as it is implemented in you. Let's say I had a picture on the path "files/user/pic.png", getpreview command get Uint8List array and output preview, make a copy of the image in the path "file/user/folder/pic.png" and the getPreview command returns [].

When I tried to find out how to get a preview in nextcloud itself on the Web, through viewing elements, I found this: "style=" background-image: url ("/core/preview?fileId=1537&c=cd6948ea3014bdb476b727556125cae9&x=238&y=238&forceIcon=0");"". As I see here, the preview of the image is taken through the file ID, in the Nextcloud API in "Listing Files" there is a line "<oc:fileid/>", I think that you need to get previews for images through this ID.

Thank you for paying attention to this problem, I am waiting for your response.

provokateurin commented 4 years ago

Ok I understand now. I'll check how to fix it in a the next days

ike20013 commented 4 years ago

For preview link look like this: http://$_baseUrl/core/preview?fileId=$picture_id&x=$width&y=$height In this link you get Base64 String in sources. I find this in DevTools "Network" in my browser. You need take id from your parse XML. I can advise you to use XML2JSON package to translate the XML tree to JSON array, and from there people could map what you need or what would your package parse through the model, I don't know how to do it correctly, I just think that parsing XML manually is time-consuming, thank you for listening.

fkleon commented 4 years ago

I've added support for retrieving oc:fileid and oc:id to WebDavClient in #14 which should allow you to get a file ID for a path.

It should be fairly easy to change the PreviewClient to accept these file IDs.

ike20013 commented 4 years ago

Yes, I see, thank you very much for your work. But in the preview/client.dart file, the preview image is still being searched via remotePath, so it should be, and instead of it, I just need to substitute the file ID? Just above I threw off an example of the link as it looks. There in the line is fileId=$id, you have in _getPreviewUrl file=${Uri.encodeQueryComponent(remotePath)}

  String _getPreviewUrl(String remotePath, int width, int height) {
    return '$_baseUrl/index.php/core/preview.png?
file=${Uri.encodeQueryComponent(remotePath)}
&x=$width&y=$height&a=1&mode=cover&forceIcon=0';
  }

and my option $_baseUrl/index.php/core/preview?fileId=$picture_id&x=$width&y=$height&a=1&mode=cover&forceIcon=0

fkleon commented 4 years ago

Yes, using the fileId URL parameter instead of file sounds exactly right.

For proper support the PreviewClient implementation would need to be changed to accept either fileId exclusively, or optionally for the getPreview, getPreviewStream and getThumbnail methods.

vauvenal5 commented 4 years ago

I think i will have some time to fix this by end of the week, since I submitted the original PreviewClient. I suggest supporting both based on this post https://help.nextcloud.com/t/getting-image-preview-with-android-library-or-via-webdav/75743/2

@ike20013 were you able to find any official documentation regarding the preview api?

ike20013 commented 4 years ago

Screenshot_24 Hello, when trying to build a project, I get the following error, how can I fix it?

vauvenal5 commented 4 years ago

@ike20013 I am not able to reproduce your issue. I wrote a test and executed it against a clean Nextcloud Docker container.

You can find the test here: https://github.com/vauvenal5/dart-nextcloud/blob/1e8ff28293fb1c26ce84009d900cc285e943568f/test/nextcloud_test.dart#L482 And the test config was as follows:

{
    "host": "http://localhost:8080",
    "username": "test",
    "password": "test",
    "shareUser": "yaga_share",
    "testDir": "files/test",
    "image": "Photos/Steps.jpg",
    "image_target": "Steps.jpg"
}

Still though it might be a good idea to offer both options, id and path, for requesting previews. :thinking:

ike20013 commented 4 years ago

This error appears regardless of what I write, as if there is simply no buildDocument, I do not know why this happens, everything that you did in the new version is very cool, I just do not know why I have such a problem. I threw the project without the build folder on another computer and tried to run the project, but got this error, I did pubget, flutter clean, gradlew clean, but nothing helped

UPD: I do not know how, but I just deleted dependencies and added it again and everything worked:D

ike20013 commented 4 years ago

I also want to add that I already gave you an example of how to get a preview of an image by ID. Since I described the problem that getting a preview of the image goes through the ID of the file, I found out when I tested the web version of nextcloud. Just if you do it through the image path, there is a problem that if you copy the image to different folders, you can get a preview only by the main path of the image. Link: http://$_baseUrl/core/preview?fileId=$picture_id&x=$width&y=$height&forceIcon=0 Maybe I can somehow get a preview through this link for the functionality that is now, or I need to have a separate function for this? Screenshot_25

vauvenal5 commented 4 years ago

I think, I am beginning to grasp what your issue is, you do not have the new path, correct? You have the path to a image and are showing a preview for this image, for example "files/user/pic.png". Then somebody moves the image on the server to a new directory, for example "files/user/folder/pic.png", and you lose your preview because you do not have the new path, correct?