Skip to content

Commit

Permalink
Fix upload of multiple files from paths
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Feb 21, 2020
1 parent c9d7a74 commit 98b060d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ Changelog
1.0a8 (unreleased)
------------------

- Nothing changed yet.
- Fix upload of multiple files from paths
[tomgross]

- Document uploading of files
[tomgross]

1.0a7 (2020-02-20)
------------------
Expand Down
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ Usage of PyFilesystem with opener
>>> opener.open_fs('pcloud://email%40example.com:SecretPassword@/')
<pCloudFS>

Uploading files

a) from filenames:

>>> pc.uploadfile(files=['/full/path/to/image1.jpg', '/Users/tom/another/image.png']

b) from data:

>>> import io
>>> from PIL import Image
>>> img = Image.open('image.jpg', 'r')
>>> bio = io.BytesIO()
>>> img.save(bio, format='jpeg')
>>> pc.uploadfile(data=bio.getvalue(), filename="image.jpg")


Documentation
-------------
Expand Down
9 changes: 2 additions & 7 deletions src/pcloud/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from hashlib import sha1
from io import BytesIO
from os.path import basename
from pcloud.validate import RequiredParameterCheck

import argparse
Expand Down Expand Up @@ -125,12 +124,8 @@ def uploadfile(self, **kwargs):
data='Hello pCloud', filename='foo.txt'
"""
if "files" in kwargs:
files = {}
upload_files = kwargs.pop("files")
for f in upload_files:
filename = basename(f)
files = {filename: open(f, "rb")}
# kwargs['filename'] = filename
upload_files = kwargs.pop("files", [])
files = [("file", open(f, "rb")) for f in upload_files]
else: # 'data' in kwargs:
files = {
"f": (kwargs.pop("filename", "data-upload.bin"), kwargs.pop("data"))
Expand Down

0 comments on commit 98b060d

Please sign in to comment.