Skip to content

Commit

Permalink
Merge pull request #356 from stripe/ob-file-upload-stringio
Browse files Browse the repository at this point in the history
Allow uploading in-memory files
  • Loading branch information
brandur-stripe authored Oct 23, 2017
2 parents a92901d + fafeffe commit 1506f4e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions stripe/api_resources/file_upload.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from stripe import api_requestor, upload_api_base, util
import stripe
from stripe import api_requestor, util
from stripe.api_resources.abstract import ListableAPIResource


Expand All @@ -7,7 +8,7 @@ class FileUpload(ListableAPIResource):

@classmethod
def api_base(cls):
return upload_api_base
return stripe.upload_api_base

@classmethod
def class_name(cls):
Expand Down
4 changes: 3 additions & 1 deletion stripe/multipart_data_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ def add_params(self, params):
self._write(self.param_header())
self._write(self.line_break)
if hasattr(value, 'read'):
filename = value.name if hasattr(value, 'name') else "blob"

self._write("Content-Disposition: form-data; name=\"")
self._write(key)
self._write("\"; filename=\"")
self._write(value.name)
self._write(filename)
self._write("\"")
self._write(self.line_break)
self._write("Content-Type: application/octet-stream")
Expand Down
5 changes: 5 additions & 0 deletions stripe/test/test_multipart_data_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import re
import sys
import StringIO

from stripe.multipart_data_generator import MultipartDataGenerator
from stripe.test.helper import StripeTestCase
Expand Down Expand Up @@ -50,3 +51,7 @@ def test_multipart_data_file_text(self):
def test_multipart_data_file_binary(self):
with open(__file__, mode='rb') as test_file:
self.run_test_multipart_data_with_file(test_file)

def test_multipart_data_stringio(self):
string = StringIO.StringIO("foo")
self.run_test_multipart_data_with_file(string)

0 comments on commit 1506f4e

Please sign in to comment.