binwiederhier / ntfy

Send push notifications to your phone or desktop using PUT/POST
https://ntfy.sh
Apache License 2.0
18.66k stars 734 forks source link

Is another webserve needed for pushing attachments outside ntfy UI? #992

Closed bertod closed 11 months ago

bertod commented 11 months ago

:question: Question Hello,

What I'm sending push notifications on my self-hosted ntfy server and I need to send attachments as well. So, what I do is to write my attachments in the attachment-cache-dir as set in the server.yml. However, when doing this, the notification I received tries to find the attachment in <base_url>/file and fails. When I create a new msg in the topic using ntfy UI, it uploads the attachment in the same dir but works.

Question Is it really possible to make ntfy finding an attachment which is stored in the cache dir without using the UI? Do I need to change some setting?

My Workaround I leverage on a different webserve (e.g., apache, nginx, whatever) and upload the attachment to it. In this way, it works (ofc, the POSTrequest header is changed accordingly)

wunter8 commented 11 months ago

ntfy does not support attachments that have been uploaded to the attachments directory by hand. When you add something by hand, ntfy doesn't know about it so it cannot attach it to any messages.

ntfy expects you to send a message to a topic with an attachment to the server (from anywhere). ntfy will extract the attachment, give it a unique ID, and save it in the attachments directory. It will then publish the message with (a link to download) the attachment to all subscribers of the topic. You can send the message with the attachment from the UI or from any other HTTP client (e.g., curl, httpie, python requests, etc.)

bertod commented 11 months ago

yeah, makes sense. The only thing is that we would end up duplicating the image and we would need to manually delete one copy. It's not a big deal, but still.

Thank you! I'm gonna close this issue :)

wunter8 commented 11 months ago

If you skip the step of putting them in the attachments directory by hand and just use the UI/curl/httpie, you won't have any duplicates and everything would still work like normal, right?