Direct link to file

  • Nextcloud Server version (e.g., 29.x.x):
    • 32.0.5
  • Operating system and version (e.g., Ubuntu 24.04):
    • kubernetes, docker image
  • Web server and version (e.g, Apache 2.4.25):
    • Apache 2.4.25
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • traefik 2.21
  • PHP version (e.g, 8.3):
    • 8.3
  • Is this the first time you’ve seen this error? (Yes / No):
    • no error
  • When did this problem seem to first start?
    • no problem
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • helm chart
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • no

Summary of the issue you are facing:

Hello,

I am new to NextCloud. I installed it on my kubernetes cluster for HA. My goal is to serve files through a file browser with some fine grained access which NextCloud seems to provide quite well.

I also need to serve some files with public access like for example embed a <img> tag in some html page with an image loaded from my NextCloud instance.

Unless I didn’t fully checked everywhere, it appears that it is not possible at all ? I found so many subject about it on internet from 2019 to this day but no one mention how to do this.

I tried to create a public link for a file, then embed it with <img src="https://mynextcloud.com/public.php/dav/files/rGXPedkfZ2ggzGR/" /> but it doesn’t work because of the response header provided by nextcloud cause brower issues to load the image.

I have read about this NextCloud plugin “Sharing path” but it appears to be not working and not maintained for a while now.

How can I embed <img> tag on my website with a file from my NextCloud instance ?

Steps to replicate it (hint: details matter!):

  1. there is no step as there is no error

Log entries

Nextcloud

Please provide the log entries from your Nextcloud log that are generated during the time of problem (via the Copy raw option from Administration settings->Logging screen or from your nextcloud.log located in your data directory). Feel free to use a pastebin/gist service if necessary.

No log as there is no error / issue

Web Browser

If the problem is related to the Web interface, open your browser inspector Console and Network tabs while refreshing (reloading) and reproducing the problem. Provide any relevant output/errors here that appear.

PASTE

Web server / Reverse Proxy

The output of your Apache/nginx/system log in /var/log/____:

PASTE HERE

Configuration

Nextcloud

The output of occ config:list system or similar is best, but, if not possible, the contents of your config.php file from /path/to/nextcloud is fine (make sure to remove any identifiable information!):

PASTE HERE

Apps

The output of occ app:list (if possible).

Tips for increasing the likelihood of a response

  • Use the preformatted text formatting option in the editor for all log entries and configuration output.
  • If screenshots are useful, feel free to include them.
    • If possible, also include key error output in text form so it can be searched for.
  • Try to edit log output only minimally (if at all) so that it can be ran through analyzers / formatters by those trying to help you.

It seems like this format works:

https://your-nextcloud-domain.com/public.php/dav/files/SHARE_TOKEN/

I tested on mine, and it directly downloads the file.

I got the Share Token from the public link that you can copy from the share screen.

Thanks but like I said in my post I already tried this link format, which is good to trigger a direct download but it’s not a direct link to serve a file, as a basic <img /> html tag with this link format will fail

ah, sorry. missed that.

what about:

https://your-nextcloud.com/index.php/s/abc123xyz/preview

This renders directly in my browser. (abc123xyz is the share token)

It doesn’t work for me, it returns me an empty bracket [] with a http code 404.
The strange part is that if I keep this format you sent me and replace the token with a fake one, I still got a 404 but I got the actual 404 Page of NextCloud instead of the empty bracket [] so Nextcloud nows something about it.

Maybe it was a feature that got removed in the latest version of NextCloud ?

Weird. I’m on 32.0.5 I believe (whatever the latest release is).

Do you get the image displayed if you insert the copied link into the browser address field?

No like I said I have an empty response in the browser with just []empty brackets.

https://my-next-cloud.com/s/SHARE_TOKEN: Link copied from Share link => It opens the Nextcloud app and shows the actual image

https://my-next-cloud-domain.com/public.php/dav/files/SHARE_TOKEN/ : Trigger a direct download of the image. Doesn’t work in a html page <img src="https://my-next-cloud-domain.com/public.php/dav/files/SHARE_TOKEN/” />

https://my-next-cloud-domain.com/index.php/s/SHARE_TOKEN/preview : Doesn’t work, returns an empty bracket and from the Chrome Dev Tool I can see that the page returns a 404.

I use latest NextCloud 32.0.5

My browser never displays empty brackets, if I call a non-existent file - but a 404.

I guess, that you did not understand, what I asked you to do:

Well good for you, mine shows an empty bracket if I call the link muzicman0 was talking about.

I’m sorry but I sent the result of what my browser was saying for the 3 different kind of link we were discussing in this topic as you didn’t precise what link you were talking about. Maybe try to be more precise about what you are asking ?

If you call the link, you want to insert as a picture, does it become displayed in the browser?

I expect either a password dialog or a message, that the link is expired.

The link I can copy directly from NextCloud ? https://my-next-cloud.com/s/SHARE_TOKEN

It opens the whole NextCloud app and open the image in the NextCloud image viewer as expected. So it doesn’t work in a embed <img /> tag as it expect a direct link to the source file, not a link to the NextCloud app.

The link is shared (extern link) so anyone who have it can access to it. There is no need for Basic Auth authentication (with username password). If I open this link on a different browser it shows me the image in the NextCloud app as well.

Thank you - so we now know, that the link is not faulty, but Nextcloud does not work as expected. - Instead of downloading the image it wants to display it in the image viewer.

Maybe the Photos-app is the reason, that the image not will be downloaded.

You are looking for → Nextcloud raw

I myself make intensive use of it, that’s why I cloned it to further develop it to my needs but that what you are trying to do is covered to 100 %

h.t.h.


ernolf

2 Likes

That looks great thanks, definitely will give it a try.

It’s crazy to me that such feature is not natively supported by NextCloud. The biggest open source file hosting server and it can’t serve basic files. Looking at the internet, there is so much people asking for this feature since 2018. There was this plugin GitHub - rookie0/nextcloud-sharing-path: 🌩 Nextcloud app to enhance files sharing to be accessed by stored path, can be used as CDN origin. a lot of people were mentionning but it’s not maintained for those last 5 years.

Anyway, I’ll give it a try and if it works I will share it over the internet for people who are looking for the same feature if that’s fine with you. Thanks

EDIT: Works like a charm, thanks again !

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.