Server: Sharing direct link to image with specific size

Created on 5 Jul 2019  路  18Comments  路  Source: nextcloud/server

Hi!

I'm a new user of Nextcloud. I have been previously using Google Photos, where it is relatively easy to get a direct public link to a photo, in any size. I often used hotlinked images in forum posts, where it's convenient to use smaller size like 640 or 800 width.

In Nextcloud you can share the picture, and then append "/preview" to the url to get direct link to jpg file. This works, but gives full size.

I noticed that I can set the size in config.php:
'preview_max_x' => 400,
'preview_max_y' => 400,

Then the /preview image will be that size, which is promising! I could almost live with this, having single fixed size for my hotlinked images... BUT, now there is no way to access the original high resolution even when viewing the files in Nextcloud! Both "Files" and "Gallery" are now showing 400*400 version.

Could these be configured separately? To have big size for Files/Gallery and smaller size when sharing direct link?

After some testing, I noticed that that there actually IS an undocumented(?) public direct url to scaled images. An example:

shared image page:

https://zuik.org/nextcloud/index.php/s/wqTbdkTyDcMndwE

Direct "/preview" link, gives 1200*1600 image in this case:

https://zuik.org/nextcloud/index.php/s/wqTbdkTyDcMndwE/preview

However, by right clicking on the image in first page, you can copy that image's url, which is:

https://zuik.org/nextcloud/index.php/apps/files_sharing/publicpreview/wqTbdkTyDcMndwE?x=1920&y=512&a=true&file=32648662_1758604047533437_6548813824810549248_o.jpg&scalingup=0

Note there is x=1920&y=512 there which can be modified to give different values. You can also remove the file= token to make it shorter. The resulting url is still globally available and can be hotlinked, which I'm hopefully proving here:

test

Only certain sizes seem to be available, though. But perhaps they could be configured somehow? Also perhaps the photo html page could have direct buttons for many sized previews?

1. to develop enhancement previews and thumbnails sharing

Most helpful comment

would you please bump the priority up a level :)

Unfortunately no :/
This is an open source project. While some are employed by nextcloud, it doesn't change that priorities cannot be forced. There are tons of features that are considered as "important" by their creator or by other users, but if there's no one to do it, well, there's no one :)

The options for you are:

  1. add some bounty to this issue so that it attract developers
  2. communicate around you to ask your surrounding devs if they can help you on this project.

In any case, we'll be happy to do our best to help anyone willing to start working on features, but no one have spare time for this (nor does for the crazy tons of requests that lays around here)

All 18 comments

@rullzer, @ChristophWurst @juliushaertl does it make sense to have?

This issue has been automatically marked as stale because it has not had recent activity and seems to be missing some essential information. It will be closed if no further activity occurs. Thank you for your contributions.

Any update on this?

Yes, would make sense to also allow those parameters i think.

Only certain sizes seem to be available, though. But perhaps they could be configured somehow? Also perhaps the photo html page could have direct buttons for many sized previews?

Yes, we only generate power of 2 sizes :)
For performances purpose, we will not change that I think.

Yes, would make sense to also allow those parameters i think.

How should we do that? We currently already allow it, so I'm guessing this pr is about adding an option to chose which size to display somehow? Or to get the direct link url?

Yeah. Currently I have to first share a link in nextcloud, then copy&paste that to a new tab, right click on the image and "copy image url". Then I can finally copy&paste that link to some forum, possibly editing the size parameters.

So, I would like to have a "share"-button which shares the image link directly. Possibly with a few different sizes. The 1024 size is fine usually, though.

There is also a cookie bug which actually prevents hotlinking images to forums, see #16298 ..

@Zuikkis for me, this just gives the preview link, I can't change the size
(was probably changed in an update as I used to be able to)

Google-Photos/Picasa and IMGur have been able to do this for years
also Gravatar is able to do this
for example:

original image: (w445-h334-no)

downscaled to 160px: (s160-no)

upscaled to 500px: (s500-no) (I don't expect nextcloud to do this though)

downscaled to 160px and cropped: (s160-c)

downscaled to 160px and smart-cropped: (s160-p)

the shared image is exactly the same

btw heads up, this image likely won't be valid for long
especially if YT terminates my account
I don't use google photos anymore and am working towards deleting my google account

but as I have thousands of images scaled with this functionality
I need nextcloud to do this as well as I'm trying to port over everything
I'm not worried about cropping, if I can just set width/height I'll be fine for now.

EDIT:
a little extra note
sXXX scales whichever dimension is greater
so if height is greater, s60 will scale height to 60px

@Tcll , it still works for me. However I'm still using server version 16.0.4, I see that 17.0.1 is available.. I hope it doesn't break it? Which version you have?

This is why I haven't closed this issue although I got it "working" myself. I'd like to hear some "official" statement what is the suggested method to hotlink images? Now I'm just relying on observed behaviour instead of following any documentation.

This page has all the images hotlinked from my nextcloud:

https://kylahullutkulkurit.fi/forum/viewtopic.php?f=2&t=6019&start=575

That's the use case for me. :) I'm currently happy with the 1024 size, but I'd like to have easier (and documented!) way to get the url.

@skjnldsv , @rullzer ?

@Zuikkis yeah it's not me in particular, my friend is the one actually hosting the cloud for me
but I believe they actually updated to 17.0.1

I actually looked again, and there's a button that allows you to copy a direct link, which actually provides a link similar to the old method you described :)

however there was a problem I had with this method in that the image wouldn't display anonymously
but I do believe that has to do with the fact my friend encrypts their cloud (something I asked for)


there's other issues I'm having with 17.0.1 though that I'm not sure were in 16.0.4
basically whenever I copy a directory via browser, the original modification dates are lost
the way to maintain them is to instead copy the local sync directory, and then move that to the public directory:

/
    Backups/
    Public/
        Files/
    Sync/
        Files/

1: copy /Sync/Files/ on your local machine and wait for it to sync.
2: move /Sync/Files (copy)/ to /Backups/Files ($date$) via browser.
that way your files will maintain their original modification dates

however there was a problem I had with this method in that the image wouldn't display anonymously
but I do believe that has to do with the fact my friend encrypts their cloud (something I asked for)

No that's probably the cookie bug which I have reported separately in https://github.com/nextcloud/server/issues/16298

Hmmh.. Maybe I dare try upgrading my cloud to nextcloud 17 and see if the pictures still work..:) I browsed through the changelogs and couldn't find anything related to this.

Ok, just upgraded to 17.0.1 and everything is still working! :) @Tcll I think you are copying the preview link instead of image url? Here's step by step. :) It's a bit difficult since my nextcloud and Firefox are in Finnish so I have to guess what the texts are in English version, but shouldn't be far off..

1) In nextcloud, view image, open sidebar and click "share link" to get the public link.

2) open that link in another tab, an example: https://zuik.org/nextcloud/index.php/s/J9BnDNfDqGmqWGg

3) Now right click on the image and select "copy image url"... This is now the url with x= y= parameters that can be edited.

If instead of "copy image url" you select "copy link" you get direct link to full size image.

Full size image from above link:
https://zuik.org/nextcloud/index.php/s/J9BnDNfDqGmqWGg/preview

Scaled to 1024:
https://zuik.org/nextcloud/index.php/apps/files_sharing/publicpreview/J9BnDNfDqGmqWGg?x=1920&y=554&a=true&file=image-20191021_155331.jpg&scalingup=0

Scaled to 256:
https://zuik.org/nextcloud/index.php/apps/files_sharing/publicpreview/J9BnDNfDqGmqWGg?x=256&y=256&a=true&file=image-20191021_155331.jpg&scalingup=0

I found the new "share direct link to image" -button also, but that indeed seems to create a link that is not publicly available..

yeah notice your "Full size" link is just the share link with /preview at the end
this is what I've basically been doing

though interestingly, now, "Copy image address" actually returns the correct result rather than the public preview link like I'd stated earlier.

but yeah, it's exactly your scaled links I was talking about that only seemed to display for me and no one else...
this was last tested before the update though, so I'm not sure if this has changed yet...

I'll make a test post in a forum and see if this works in an incognito window in a bit

EDIT:
well, everything seems to work, buuut I've been tricked by stuff before...
one issue I'm having with it though is I can't seem to downscale a 640x480 image to 160x120...
lowest it scales to is 256x192...
meaning I can't use this for vault preview images on one particular site yet...

this issue may also interfere with a few documentation threads...
hopefully there's an unexplained param override
neither me nor my friend are really worried about slower performance
(unless it's like python-level slow, which is probably something that seriously needs to be fixed within nextcloud)

it should be able to match google in terms of basic resizing/cropping without issue
maybe even an additional value to offset the crop (similar to google's smart-crop result)

This is marked as to develop, but is low in our priority list, please stop asking for updates. Or just start implementing it yourself and copen a pull request.
Unless someone else want to take a dive at it, no one is currently implementing this. Please be patient, we're only having 24h in each day! :)

but is low in our priority list

that's exactly why I'm asking, pulling my data off google is starting to become urgent...
I've been waiting for almost a year now...
if I wasn't busy writing 5 other projects (not on here, I use GitLab which better represents FOSS), I'd absolutely lend a hand. ;)

would you please bump the priority up a level :)
if youtube terminates my account Dec 10, I would like to be able to delete my google account.
(evil corporate entities, data collection, and blah blah I don't support it) :P

would you please bump the priority up a level :)

Unfortunately no :/
This is an open source project. While some are employed by nextcloud, it doesn't change that priorities cannot be forced. There are tons of features that are considered as "important" by their creator or by other users, but if there's no one to do it, well, there's no one :)

The options for you are:

  1. add some bounty to this issue so that it attract developers
  2. communicate around you to ask your surrounding devs if they can help you on this project.

In any case, we'll be happy to do our best to help anyone willing to start working on features, but no one have spare time for this (nor does for the crazy tons of requests that lays around here)

dang, I understand though, and I'll see what I can do ;)

option 1 isn't an option for me, as me and everyone around me who supports me all work for free for the better... (donations are fine)

for option 2, while I don't have any immediate surrounding devs (yeah I'm literally just one dude working on 5 priority projects out of probably 12 or 15 projects total), I do know a few groups who might have a few takers if I can manage to get in contact with them. :)

For me, size 1024 is enough, and I'm reasonably happy with the way it works now. However, these "/apps/files_sharing/publicpreview/" urls are not documented so in theory some nextcloud dev could change them and then all my hotlinked images won't work anymore. So @skjnldsv maybe you can comment on this, are these urls likely to stay?

@Tcll, nextcloud only generates previews for sizes 64, 256, 1024, 4096. Each step multiple by 4 from the previous. So next smaller step from 256x192 would be 64x48.. If you request different size, it will use the next higher step (so 256 for 160 width).. In a perfect world, you could have some config which sizes you need. :)

@Zuikkis I was suggesting for generating any size
I did some heavy playing around with it (x,y,a) and have gotten sizes like 128x64 (120,60,false), 256x171 (120,80,false), or 256x102 (200,80,false) or even as awkward as 85x64 (80,120,true)...
it's pretty weird how it behaves :P

but yeah, it can semi-crop already if you work it properly

Was this page helpful?
0 / 5 - 0 ratings