Docs docs docs
This commit is contained in:
parent
762333c28f
commit
034c81288c
11 changed files with 346 additions and 141 deletions
152
docs/publish.md
152
docs/publish.md
|
@ -659,26 +659,33 @@ Here's an example that will open Reddit when the notification is clicked:
|
|||
]));
|
||||
```
|
||||
|
||||
## Attachments (send files)
|
||||
## Attachments
|
||||
You can send images and other files to your phone as attachments to a notification. The attachments are then downloaded
|
||||
onto your phone (depending on size and setting automatically), and can be used from the Downloads folder.
|
||||
|
||||
There are two different ways to send attachments, either via PUT or by passing an external URL.
|
||||
There are two different ways to send attachments:
|
||||
|
||||
**Upload attachments from your computer**: To send an attachment from your computer as a file, you can send it as the
|
||||
PUT request body. If a message is greater than the maximum message size or consists of non-UTF-8 characters, the ntfy
|
||||
server will automatically detect the mime type and size, and send the message as an attachment file.
|
||||
* sending [a local file](#attach-local-file) via PUT, e.g. from `~/Flowers/flower.jpg` or `ringtone.mp3`
|
||||
* or by [passing an external URL](#attach-file-from-a-url) as an attachment, e.g. `https://f-droid.org/F-Droid.apk`
|
||||
|
||||
You can optionally pass a filename (or force attachment mode for small text-messages) by passing the `X-Filename` header
|
||||
or query parameter (or any of its aliases `Filename`, `File` or `f`).
|
||||
### Attach local file
|
||||
To send an attachment from your computer as a file, you can send it as the PUT request body. If a message is greater
|
||||
than the maximum message size (4,096 bytes) or consists of non UTF-8 characters, the ntfy server will automatically
|
||||
detect the mime type and size, and send the message as an attachment file. To send smaller text-only messages or files
|
||||
as attachments, you must pass a filename by passing the `X-Filename` header or query parameter (or any of its aliases
|
||||
`Filename`, `File` or `f`).
|
||||
|
||||
By default, and how ntfy.sh is configured, the **max attachment size is 15 MB** (with 100 MB total per visitor).
|
||||
Attachments **expire after 3 hours**, which typically is plenty of time for the user to download it, or for the Android app
|
||||
to auto-download it. Please also check out the [other limits below](#limitations).
|
||||
|
||||
Here's an example showing how to upload an image:
|
||||
|
||||
|
||||
=== "Command line (curl)"
|
||||
```
|
||||
curl \
|
||||
-T flower.jpg \
|
||||
-H "Filename: flower.jpg" \
|
||||
ntfy.sh/flowers
|
||||
```
|
||||
|
||||
|
@ -693,6 +700,7 @@ Here's an example showing how to upload an image:
|
|||
``` http
|
||||
PUT /flowers HTTP/1.1
|
||||
Host: ntfy.sh
|
||||
Filename: flower.jpg
|
||||
|
||||
<binary JPEG data>
|
||||
```
|
||||
|
@ -701,7 +709,8 @@ Here's an example showing how to upload an image:
|
|||
``` javascript
|
||||
fetch('https://ntfy.sh/flowers', {
|
||||
method: 'PUT',
|
||||
body: document.getElementById("file").files[0]
|
||||
body: document.getElementById("file").files[0],
|
||||
headers: { 'Filename': 'flower.jpg' }
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -709,44 +718,108 @@ Here's an example showing how to upload an image:
|
|||
``` go
|
||||
file, _ := os.Open("flower.jpg")
|
||||
req, _ := http.NewRequest("PUT", "https://ntfy.sh/flowers", file)
|
||||
req.Header.Set("Filename", "flower.jpg")
|
||||
http.DefaultClient.Do(req)
|
||||
```
|
||||
|
||||
=== "Python"
|
||||
``` python
|
||||
requests.put("https://ntfy.sh/flowers",
|
||||
data=open("flower.jpg", 'rb'))
|
||||
data=open("flower.jpg", 'rb'),
|
||||
headers={ "Filename": "flower.jpg" })
|
||||
```
|
||||
|
||||
=== "PHP"
|
||||
``` php-inline
|
||||
file_get_contents('https://ntfy.sh/reddit_alerts', false, stream_context_create([
|
||||
file_get_contents('https://ntfy.sh/flowers', false, stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'PUT',
|
||||
'content' => XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxx
|
||||
'header' =>
|
||||
"Content-Type: application/octet-stream\r\n" . // Does not matter
|
||||
"Filename: flower.jpg",
|
||||
'content' => file_get_contents('flower.jpg') // Dangerous for large files
|
||||
]
|
||||
]));
|
||||
```
|
||||
|
||||
```
|
||||
- Uploaded attachment
|
||||
- External attachment
|
||||
- Preview without attachment
|
||||
Here's what that looks like on Android:
|
||||
|
||||
<figure markdown>
|
||||
{ width=500 }
|
||||
<figcaption>Image attachment sent from a local file</figcaption>
|
||||
</figure>
|
||||
|
||||
# Upload and send attachment with custom message and filename
|
||||
curl \
|
||||
-T flower.jpg \
|
||||
-H "Message: Here's a flower for you" \
|
||||
-H "Filename: flower.jpg" \
|
||||
ntfy.sh/howdy
|
||||
### Attach file from a URL
|
||||
Instead of sending a local file to your phone, you can use an external URL to specify where the attachment is hosted.
|
||||
This could be a Google Drive or Dropbox link, or any other publicly available URL. The ntfy server will briefly probe
|
||||
the URL to retrieve type and size for you. Since the files are externally hosted, the expiration or size limits from
|
||||
above do not apply here.
|
||||
|
||||
# Send external attachment from other URL, with custom message
|
||||
curl \
|
||||
-H "Attachment: https://example.com/files.zip" \
|
||||
"ntfy.sh/howdy?m=Important+documents+attached"
|
||||
To attach an external file, simple pass the `X-Attach` header or query parameter (or any of its aliases `Attach` or `a`)
|
||||
to specify the attachment URL. It can be any type of file.
|
||||
|
||||
Here's an example showing how to upload an image:
|
||||
|
||||
=== "Command line (curl)"
|
||||
```
|
||||
curl \
|
||||
-X POST \
|
||||
-H "Attach: https://f-droid.org/F-Droid.apk" \
|
||||
ntfy.sh/mydownloads
|
||||
```
|
||||
|
||||
=== "ntfy CLI"
|
||||
```
|
||||
ntfy publish \
|
||||
--attach="https://f-droid.org/F-Droid.apk" \
|
||||
mydownloads
|
||||
```
|
||||
|
||||
=== "HTTP"
|
||||
``` http
|
||||
POST /mydownloads HTTP/1.1
|
||||
Host: ntfy.sh
|
||||
Attach: https://f-droid.org/F-Droid.apk
|
||||
```
|
||||
|
||||
=== "JavaScript"
|
||||
``` javascript
|
||||
fetch('https://ntfy.sh/mydownloads', {
|
||||
method: 'POST',
|
||||
headers: { 'Attach': 'https://f-droid.org/F-Droid.apk' }
|
||||
})
|
||||
```
|
||||
|
||||
=== "Go"
|
||||
``` go
|
||||
req, _ := http.NewRequest("POST", "https://ntfy.sh/mydownloads", file)
|
||||
req.Header.Set("Attach", "https://f-droid.org/F-Droid.apk")
|
||||
http.DefaultClient.Do(req)
|
||||
```
|
||||
|
||||
=== "Python"
|
||||
``` python
|
||||
requests.put("https://ntfy.sh/mydownloads",
|
||||
headers={ "Attach": "https://f-droid.org/F-Droid.apk" })
|
||||
```
|
||||
|
||||
=== "PHP"
|
||||
``` php-inline
|
||||
file_get_contents('https://ntfy.sh/mydownloads', false, stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'PUT',
|
||||
'header' =>
|
||||
"Content-Type: text/plain\r\n" . // Does not matter
|
||||
"Attach: https://f-droid.org/F-Droid.apk",
|
||||
]
|
||||
]));
|
||||
```
|
||||
|
||||
<figure markdown>
|
||||
{ width=500 }
|
||||
<figcaption>File attachment sent from an external URL</figcaption>
|
||||
</figure>
|
||||
|
||||
```
|
||||
|
||||
## E-mail notifications
|
||||
You can forward messages to e-mail by specifying an address in the header. This can be useful for messages that
|
||||
|
@ -1029,17 +1102,20 @@ parameter (or any of its aliases `unifiedpush` or `up`) to `1` to [disable Fireb
|
|||
option is equivalent to `Firebase: no`, but was introduced to allow future flexibility.
|
||||
|
||||
## Limitations
|
||||
There are a few limitations to the API to prevent abuse and to keep the server healthy. Most of them you won't run into,
|
||||
There are a few limitations to the API to prevent abuse and to keep the server healthy. Almost all of these settings
|
||||
are configurable via the server side [rate limiting settings](config.md#rate-limiting). Most of these limits you won't run into,
|
||||
but just in case, let's list them all:
|
||||
|
||||
| Limit | Description |
|
||||
|---|---|
|
||||
| **Message length** | Each message can be up to 4,096 bytes long. Longer messages are truncated. |
|
||||
| **Requests** | By default, the server is configured to allow 60 requests at once, and then refills the your allowed requests bucket at a rate of one request per 10 seconds. You can read more about this in the [rate limiting](config.md#rate-limiting) section. |
|
||||
| **E-mails** | By default, the server is configured to allow sending 16 e-mails at once, and then refills the your allowed e-mail bucket at a rate of one per hour. You can read more about this in the [rate limiting](config.md#rate-limiting) section. |
|
||||
| **Subscription limits** | By default, the server allows each visitor to keep 30 connections to the server open. |
|
||||
| **Bandwidth** | By default, the server allows 500 MB of GET/PUT/POST traffic for attachments per visitor in a 24 hour period. Traffic exceeding that is rejected. |
|
||||
| **Total number of topics** | By default, the server is configured to allow 15,000 topics. The ntfy.sh server has higher limits though. |
|
||||
| Limit | Description |
|
||||
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| **Message length** | Each message can be up to 4,096 bytes long. Longer messages are treated as [attachments](#attachments). |
|
||||
| **Requests** | By default, the server is configured to allow 60 requests per visitor at once, and then refills the your allowed requests bucket at a rate of one request per 10 seconds. |
|
||||
| **E-mails** | By default, the server is configured to allow sending 16 e-mails per visitor at once, and then refills the your allowed e-mail bucket at a rate of one per hour. |
|
||||
| **Subscription limit** | By default, the server allows each visitor to keep 30 connections to the server open. |
|
||||
| **Attachment size limit** | By default, the server allows attachments up to 15 MB in size, up to 100 MB in total per visitor and up to 5 GB across all visitors. |
|
||||
| **Attachment expiry** | By default, the server deletes attachments after 3 hours and thereby frees up space from the total visitor attachment limit. |
|
||||
| **Attachment bandwidth** | By default, the server allows 500 MB of GET/PUT/POST traffic for attachments per visitor in a 24 hour period. Traffic exceeding that is rejected. |
|
||||
| **Total number of topics** | By default, the server is configured to allow 15,000 topics. The ntfy.sh server has higher limits though. |
|
||||
|
||||
## List of all parameters
|
||||
The following is a list of all parameters that can be passed when publishing a message. Parameter names are **case-insensitive**,
|
||||
|
@ -1053,8 +1129,8 @@ and can be passed as **HTTP headers** or **query parameters in the URL**. They a
|
|||
| `X-Tags` | `Tags`, `Tag`, `ta` | [Tags and emojis](#tags-emojis) |
|
||||
| `X-Delay` | `Delay`, `X-At`, `At`, `X-In`, `In` | Timestamp or duration for [delayed delivery](#scheduled-delivery) |
|
||||
| `X-Click` | `Click` | URL to open when [notification is clicked](#click-action) |
|
||||
| `X-Attach` | `Attach`, `a` | URL to send as an [attachment](#attachments-send-files), as an alternative to PUT/POST-ing an attachment |
|
||||
| `X-Filename` | `Filename`, `file`, `f` | Optional [attachment](#attachments-send-files) filename, as it appears in the client |
|
||||
| `X-Attach` | `Attach`, `a` | URL to send as an [attachment](#attachments), as an alternative to PUT/POST-ing an attachment |
|
||||
| `X-Filename` | `Filename`, `file`, `f` | Optional [attachment](#attachments) filename, as it appears in the client |
|
||||
| `X-Email` | `X-E-Mail`, `Email`, `E-Mail`, `mail`, `e` | E-mail address for [e-mail notifications](#e-mail-notifications) |
|
||||
| `X-Cache` | `Cache` | Allows disabling [message caching](#message-caching) |
|
||||
| `X-Firebase` | `Firebase` | Allows disabling [sending to Firebase](#disable-firebase) |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue