Repo Downloads API
- List downloads for a repository
- Get a single download
- Create a new download (Part 1: Create the resource)
- Create a new download (Part 2: Upload file to s3)
- Delete a download
The downloads API is for package downloads only. If you want to get source tarballs you should use this instead.
List downloads for a repository
GET /repos/:owner/:repo/downloads
Response
Status: 200 OK
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
[
{
"url": "https://api.github.com/repos/octocat/Hello-World/downloads/1",
"html_url": "https://github.com/repos/octocat/Hello-World/downloads/new_file.jpg",
"id": 1,
"name": "new_file.jpg",
"description": "Description of your download",
"size": 1024,
"download_count": 40,
"content_type": ".jpg"
}
]
Get a single download
GET /repos/:owner/:repo/downloads/:id
Response
Status: 200 OK
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
{
"url": "https://api.github.com/repos/octocat/Hello-World/downloads/1",
"html_url": "https://github.com/repos/octocat/Hello-World/downloads/new_file.jpg",
"id": 1,
"name": "new_file.jpg",
"description": "Description of your download",
"size": 1024,
"download_count": 40,
"content_type": ".jpg"
}
Create a new download (Part 1: Create the resource)
Creating a new download is a two step process. You must first create a new download resource.
POST /repos/:owner/:repo/downloads
Input
- name
- Required string
- size
- Required number - Size of file in bytes.
- description
- Optional string
- content_type
- Optional string
{
"name": "new_file.jpg",
"size": 114034,
"description": "Latest release",
"content_type": "text/plain"
}
Response
Status: 201 Created
Location: https://api.github.com/user/repo/downloads/1
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
{
"url": "https://api.github.com/repos/octocat/Hello-World/downloads/1",
"html_url": "https://github.com/repos/octocat/Hello-World/downloads/new_file.jpg",
"id": 1,
"name": "new_file.jpg",
"description": "Description of your download",
"size": 1024,
"download_count": 40,
"content_type": ".jpg",
"policy": "ewogICAg...",
"signature": "mwnFDC...",
"bucket": "github",
"accesskeyid": "1ABCDEFG...",
"path": "downloads/octocat/Hello-World/new_file.jpg",
"acl": "public-read",
"expirationdate": "2011-04-14T16:00:49Z",
"prefix": "downloads/octocat/Hello-World/",
"mime_type": "image/jpeg",
"redirect": false,
"s3_url": "https://github.s3.amazonaws.com/"
}
Create a new download (Part 2: Upload file to s3)
Now that you have created the download resource, you can use the
information in the response to upload your file to s3. This can be done
with a POST to the s3_url you got in the create response. Here is a
brief example using curl:
curl \
-F "key=downloads/octocat/Hello-World/new_file.jpg" \
-F "acl=public-read" \
-F "success_action_status=201" \
-F "Filename=new_file.jpg" \
-F "AWSAccessKeyId=1ABCDEF..." \
-F "Policy=ewogIC..." \
-F "Signature=mwnF..." \
-F "Content-Type=image/jpeg" \
-F "file=@new_file.jpg" \
https://github.s3.amazonaws.com/
NOTES
The order in which you pass these fields matters! Follow the order shown above exactly. All parameters shown are required and if you excluded or modify them your upload will fail because the values are hashed and signed by the policy.
- key
- Value of
pathfield in the response. - acl
- Value of
aclfield in the response. - success_action_status
- 201, or whatever you want to get back.
- Filename
- Value of
namefield in the response. - AWSAccessKeyId
- Value of
accesskeyidfield in the response. - Policy
- Value of
policyfield in the response. - Signature
- Value of
signaturefield in the response. - Content-Type
- Value of
mime_typefield in the response. - file
- Local file. Example assumes the file existing in the directory where
you are running the curl command. Yes, the
@matters.
More information about using the REST API to interact with s3 can be found here.
Delete a download
DELETE /repos/:owner/:repo/downloads/:id
Response
Status: 204 No Content
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999