From 501caf767bc6e240a8e4e2f74a8551c2b61b77ee Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Wed, 29 Aug 2018 10:40:04 -0400 Subject: [PATCH] Upload with a temp file instead of streaming Using a stream is a no-go due to a bug in libcloud: https://issues.apache.org/jira/browse/LIBCLOUD-935?focusedCommentId=16152982&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-16152982 Instead, write the uploaded file to a named tempfile and pass that to the uploader. --- atst/uploader.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/atst/uploader.py b/atst/uploader.py index 9f1ef62a..e63ba4ce 100644 --- a/atst/uploader.py +++ b/atst/uploader.py @@ -1,4 +1,6 @@ +from tempfile import NamedTemporaryFile from uuid import uuid4 + from libcloud.storage.types import Provider from libcloud.storage.providers import get_driver @@ -26,13 +28,13 @@ class Uploader: ) object_name = uuid4().hex - self.container.driver._put_object( - stream=iter(fyle.stream), - container=self.container, - object_name=object_name, - verify_hash=False, - extra={"acl": "private"}, - ) + with NamedTemporaryFile() as tempfile: + tempfile.write(fyle.stream.read()) + self.container.upload_object( + file_path=tempfile.name, + object_name=object_name, + extra={"acl": "private"}, + ) return (fyle.filename, object_name) def download(self, path):