Skip to content

Commit f1d6f5d

Browse files
committed
Use the request library for file upload
1 parent 4a8786f commit f1d6f5d

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

github3/models.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"""
77

88
from .helpers import to_python, to_api
9-
9+
from .config import settings
10+
import requests
1011

1112
class BaseResource(object):
1213
"""A BaseResource object."""
@@ -181,29 +182,25 @@ def create_download(self, filepath, **params):
181182
data = {'size': os.path.getsize(filepath), 'name': filepath.split('/')[-1]}
182183

183184
dlressource = self._gh._post_resource(('repos', self.owner.login,
184-
self.name, 'downloads'), DownloadRessource, data=self._gh._resource_serialize(data), **params)
185-
186-
curl_command = list();
187-
curl_command.append('curl')
188-
curl_command.append('-s')
189-
curl_command.append('-F key='+dlressource.path)
190-
curl_command.append('-F acl='+dlressource.acl)
191-
curl_command.append('-F success_action_status=201')
192-
curl_command.append('-F Filename='+dlressource.name)
193-
curl_command.append('-F AWSAccessKeyId='+dlressource.accesskeyid)
194-
curl_command.append('-F Policy='+dlressource.policy)
195-
curl_command.append('-F Signature='+dlressource.signature)
196-
curl_command.append('-F Content-Type='+dlressource.mime_type)
197-
curl_command.append('-F file=@'+filepath+'')
198-
curl_command.append('https://github.s3.amazonaws.com/')
199-
import subprocess
200-
p = subprocess.Popen(curl_command,
201-
env=os.environ,
202-
stdin=subprocess.PIPE,
203-
stdout=subprocess.PIPE,
204-
stderr=subprocess.PIPE,
205-
)
206-
out, err = p.communicate()
185+
self.name, 'downloads'),
186+
DownloadRessource,
187+
data=self._gh._resource_serialize(data),
188+
**params)
189+
form = {}
190+
form['key'] = dlressource.path
191+
form['acl'] = dlressource.acl
192+
form['success_action_status'] = '201'
193+
form['Filename'] = dlressource.name
194+
form['AWSAccessKeyId'] = dlressource.accesskeyid
195+
form['Policy'] = dlressource.policy
196+
form['Signature'] = dlressource.signature
197+
form['Content-Type'] = dlressource.mime_type
198+
199+
myfile = open(filepath)
200+
201+
files = {'file' : myfile}
202+
203+
r = requests.post(settings.github_upload_file_url, data=form, files=files, **params)
207204
return dlressource;
208205

209206

0 commit comments

Comments
 (0)