|
6 | 6 |
|
7 | 7 | """ |
8 | 8 |
|
9 | | -from base64 import b64decode |
| 9 | +from base64 import b64decode, b64encode |
10 | 10 | from time import time |
11 | 11 | from json import dumps |
12 | 12 | import requests |
13 | 13 | from .issue import Issue, Label, Milestone, issue_params |
14 | 14 | from .git import Blob, Commit, Reference, Tag |
15 | 15 | from .models import GitHubCore, BaseComment, BaseCommit |
16 | 16 | from .pulls import PullRequest |
17 | | -from .structs import OrderedDict |
18 | 17 | from .user import User, Key |
19 | 18 |
|
20 | 19 |
|
@@ -246,24 +245,27 @@ def create_download(self, name, path, description='', |
246 | 245 | json = self._post(url, data) |
247 | 246 |
|
248 | 247 | if json: |
249 | | - form = [('key', json.get('path')), ('acl', json.get('acl')), |
| 248 | + form_vals = [('key', json.get('path')), |
| 249 | + ('acl', json.get('acl')), |
250 | 250 | ('success_action_status', '201'), |
251 | 251 | ('Filename', json.get('name')), |
252 | | - ('Expires', int(time()) + 100), |
253 | 252 | ('AWSAccessKeyId', json.get('accesskeyid')), |
254 | 253 | ('Policy', json.get('policy')), |
255 | 254 | ('Signature', json.get('signature')), |
256 | 255 | ('Content-Type', json.get('mime_type')), |
257 | | - ('file', {json.get('name'): open(path, 'rb').read()})] |
258 | | - #files = {json.get('name'): open(path, 'rb')} |
259 | | - #resp = requests.post(json.get('s3_url'), # headers=headers, |
260 | | - # data=form, files=files) |
261 | | - #headers = {'Authorization': 'AWS {0}:{1}'.format( |
262 | | - # json.get('accesskeyid'), json.get('signature'))} |
263 | | - resp = requests.post(json.get('s3_url'), data=OrderedDict(form), |
264 | | - headers=headers) |
265 | | - #resp = requests.post('http://httpbin.org/post', headers=headers, |
266 | | - # files=form) |
| 256 | + ('file', b64encode(open(path, 'rb').read()))] |
| 257 | +# form = """--github |
| 258 | +#Content-Disposition: form-data; name="{key}" |
| 259 | +# |
| 260 | +#{value} |
| 261 | +#""" |
| 262 | +# data = '' |
| 263 | +# for (k, v) in form_vals: |
| 264 | +# data = ''.join([data, form.format(key=k, value=v)]) |
| 265 | +# data = ''.join([data, '--github--']) |
| 266 | +# headers = {'Content-Type': 'multipart/form-data; boundary=github', |
| 267 | +# 'Content-Length': str(len(data))} |
| 268 | + resp = requests.post(json.get('s3_url'), data=form_vals) |
267 | 269 | print(resp) |
268 | 270 | print(resp.content) |
269 | 271 |
|
|
0 commit comments