owncloud / ios-library

MIT License
77 stars 90 forks source link

Added parameters dictionary to OCWebDavClient's download path #64

Closed eliburke closed 9 years ago

eliburke commented 9 years ago

You may prefer to re-work this so that the existing API does not change, but I was trying to keep the patch simple. The library changes are easy: add a dictionary for url parameters to downloadFile, and pass it through to OCWebDavClient and into the request object. Note that I also made the progress and background handlers optional.

The meat of the change is in the example app, which I tweaked to have three different download buttons. One of them will download a preview image. I put in a couple of comments that explain what is going on. A specific (unchanging) URL is requested with URL parameters to indicate the file that should be previewed, it's size, and whether or not its aspect should be preserved.

A better implementation of this might be to add a preview specific API to OCCommunicationLib, or perhaps move the bulk of downloadPreviewImage into OCFileDto, but there are a lot of different ways to scramble this egg.

jancborchardt commented 9 years ago

Hey @eliburke you’re very welcome in our IRC channel #owncloud-ios (on freenode)! :)

ggdiez commented 9 years ago

Hey @eliburke

We are studying your pull request. I tried to download thumbnails using your code in the example but I have problems, the "downloadFilePreview" method download an unreadable file for the "UIImage".

This is the unreadble file: https://s3.owncloud.com/owncloud/public.php?service=files&t=a222cf9c2a47f46c4f3175915c39178a

Tested in ownCloud server version: 7.0.3 RC1 I use url like this: https://example.com/version_server/owncloud/index.php/core/ts.png

Any idea of what is happening?

eliburke commented 9 years ago

If you look at your unreadable file with a text editor, you'll see that it is actually HTML. I think you may not be using the correct path for the preview URL. It should look something like this: https://example.com/version_server/index.php/core/preview.png I'm using what I think is a stock 7.0.2 install. Using your sample URL, I'd guess this should work for you: https://s3.owncloud.com/owncloud/index.php/core/preview.php If that doesn't work, you may need to look at HTML page source in a browser to see how your preview URL is different.

Once you have the URL, you can test it in a browser by adding URL parameters: https://example.com/version_server/index.php/core/preview.png?file=%2Fphotos%2Fparis.jpg&x=256&y=256 %2F is a forward slash '/' so this example is telling the preview script to generate a thumbnail for "/photos/paris.jpg" The path must start from the root of the WebDav directory.

ggdiez commented 9 years ago

Thank you for your last link, this help me to understand the process. I was using a incorrect path for the preview URL.

LukasReschke commented 9 years ago

Preview.png is the wrong URL. Please don't use private methods of the server. Use the official API instead: https://github.com/owncloud/core/blob/f8421958b3d06379c9dbfec49a16cf072dff7591/apps/files/appinfo/routes.php#L12

=> index.php/apps/files//api/v1/thumbnail/{x}/{y}/{file}

eliburke commented 9 years ago

Yes, using an official API is preferred. In my defense, the new thumbnail route was not available (or documented anywhere publicly) in an official release when I was working on this PR. :-) Thanks for the heads up.

rperezb commented 9 years ago

Thanks for this pull request, we have to close it since as @LukasReschke said, this is not using the official API. You are more than welcome to do another pull request.

thx!