You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-18
Original file line number
Diff line number
Diff line change
@@ -12,39 +12,65 @@ Highlights include:
12
12
- Low memory: the files are streamed out to the client immediately
13
13
- Low CPU: the default server doesn't compress files, only packages them into a zip, so there's minimal CPU load (configurable)
14
14
- High concurrency: the two properties above allow a single small server to stream hundreds of large zips simultaneous
15
-
- It includes a HTTP server, but can be used as a library (see zip_streamer.go).
15
+
- It includes a HTTP server, but can be used as a library (see `zip_streamer.go`)
16
16
17
-
## HTTP Endpoints
17
+
## JSON Zip File Descriptor
18
18
19
-
**POST /download**
19
+
Each HTTP endpoint requires a JSON description of the desired zip file.
20
20
21
-
This endpoint takes a post, and returns a zip file.
21
+
The JSON format root object should have an "entries" property, which holds an array of the files. Each entry requires 2 properties:
22
22
23
-
It expects a JSON body defining which files to include in the zip. The `ZipPath` is the path and filename in the resulting zip file (it should be a relative path).
23
+
-`Url` REQUIRED: the URL of the file to include in the zip. Zipstreamer will fetch this via a GET request. The file must be public; if it is private, most file hosts provide query string authentication options for private files, which work well with Zipstreamer (example [AWS S3 Docs](https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html)).
24
+
-`ZipPath` REQUIRED: the path and filename where this entry should appear in the resulting zip file. This is a relative path to the root of the zip file.
This endpoint creates a temporary link which can be used to download a zip via a GET. This is helpful as on a webapp it can be painful to POST results, and trigger a "Save File" popup with the result. With this, you can create the link in a POST, then open the download link in a new window.
45
+
### POST /download
39
46
40
-
*Important*:
47
+
This endpoint takes a http POST body containing the JSON description of the desired zip file, and returns a zip file.
48
+
49
+
### GET /download
50
+
51
+
Returns a zip file, from a JSON zip description hosted on another server. This is useful over the POST endpoint in a few use cases:
52
+
53
+
- You want to hide from the client where the original files are hosted (see zsid parameter)
54
+
- Use cases where POST requests aren't easy to adopt (traditional static webpages)
55
+
- You want to trigger a browsers' "Save File" UI, which isn't shown for POST requests. See `POST /create_download_link` as an alternative if you prefer writing this logic client side.
41
56
42
-
- These links are only live for 60 seconds. They are expected to be used immediately and are not long living.
43
-
- This stores the link in an in memory cache, so it's not suitable for deploying to a multi-server cluster without extra configuration. If you are hosting a multi-server cluster make sure to enable Session Affinity on your host, so that requests from a given client are routed to a consistent correct host. See the deploy section for details on Heroku and Google Cloud Run.
57
+
This endpoint requires one of two query parameters describing where to find the JSON descriptor. If both are provided, only `zsurl` will be used:
58
+
59
+
-`zsurl`: the full URL to the JSON file describing the zip. Example: `zipstreamer.yourserver.com/download?zsurl=https://gist.githubusercontent.com/scosman/449df713f97888b931c7b4e4f76f82b1/raw/82a1b54cd20ab44a916bd76a5b5d866acee2b29a/listfile.json`
60
+
-`zsid`: must be used with the `ZS_LISTFILE_URL_PREFIX` environment variable. The JSON file will be fetched from `ZS_LISTFILE_URL_PREFIX + zsid`. This allows you to hide the full URL path from clients, revealing only the end of the URL. Example: `ZS_LISTFILE_URL_PREFIX = "https://gist.githubusercontent.com/scosman/"` and `zipstreamer.yourserver.com/download?zsid=449df713f97888b931c7b4e4f76f82b1/raw/82a1b54cd20ab44a916bd76a5b5d866acee2b29a/listfile.json`
61
+
62
+
### POST /create_download_link
63
+
64
+
This endpoint takes the JSON zip description in the POST body, stores it in a local cache, allowing the caller to fetch the zip file via an additional call to `GET /download_link/{link_id}`.
65
+
66
+
This is useful for if you want to trigger a browser "Save File" UI, which isn't shown for POST requests. See `GET /download` if you prefer a server-driven approach.
67
+
68
+
*Important*:
44
69
45
-
It expects the same body format as `/download`.
70
+
- These links only live for 60 seconds. They are expected to be used immediately.
71
+
- This stores the link in an in-memory cache, so it's not suitable for deploying to a multi-server cluster without extra configuration. If you are hosting a multi-server cluster, see the deployment section for options.
46
72
47
-
Here is an example response body:
73
+
Here is an example response body containing the link ID. See docs for `GET /download_link/{link_id}` below for how to fetch the zip file:
48
74
49
75
```
50
76
{
@@ -53,7 +79,7 @@ Here is an example response body:
53
79
}
54
80
```
55
81
56
-
**GET /download_link/{link_id}**
82
+
### GET /download_link/{link_id}
57
83
58
84
Call this endpoint with a `link_id` generated with `/create_download_link` to download that zip file.
@@ -106,6 +132,7 @@ These ENV vars can be used to config the server:
106
132
-`PORT` - Defaults to 4008. Sets which port the HTTP server binds to.
107
133
-`ZS_URL_PREFIX` - If set, requires that the URL of files downloaded start with this prefix. Useful to preventing others from using your server to serve their files.
108
134
-`ZS_COMPRESSION` - Defaults to no compression. It's not universally known, but zip files can be uncompressed, and used as a simple packaging format (combined many files into one). Set to `DEFLATE` to use zip deflate compression. **WARNING - enabling compression uses CPU, and will greatly reduce throughput of server**. Note: for file formats already optimized for size (JPEGs, MP4s), zip compression will often increase the total zip file size.
135
+
-`ZS_LISTFILE_URL_PREFIX` - See documentation for `GET /download`
0 commit comments