Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow uploading in-memory files #356

Merged
merged 1 commit into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opportunistic fix to ensure that the current value of upload_api_base is used (before, the value was only read once when the library is loaded).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find.


@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)