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

Dropbox storage throws an exception when saving a file #378

Closed
maxmalysh opened this issue Aug 10, 2017 · 4 comments
Closed

Dropbox storage throws an exception when saving a file #378

maxmalysh opened this issue Aug 10, 2017 · 4 comments

Comments

@maxmalysh
Copy link
Contributor

maxmalysh commented Aug 10, 2017

Dropbox storage backend throws an exception when saving a file. I guess it stopped working after the API upgrade (see e46f306 and #302).

How to reproduce:

$ touch foo.txt
$ echo "hello, world" >> foo.txt
$ python3 manage.py shell
>>> from storages.backends.dropbox import DropBoxStorage
>>> dropbox_key = 'OAUTH_ACCESS_TOKEN'
>>> dropbox_storage = DropBoxStorage(dropbox_key)
>>> 
>>> f = open('foo.txt', 'rb')
>>> dropbox_storage.save('foo.txt', f)
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/[...]/venv/lib/python3.5/site-packages/django/core/files/storage.py", line 54, in save
    return self._save(name, content)
  File "/[...]/venv/lib/python3.5/site-packages/storages/backends/dropbox.py", line 111, in _save
    self.client.files_upload(content, self._full_path(name))
  File "/[...]/venv/lib/python3.5/site-packages/dropbox/base.py", line 1267, in files_upload
    f,
  File "/[...]/venv/lib/python3.5/site-packages/dropbox/dropbox.py", line 234, in request
    timeout=timeout)
  File "/[...]/venv/lib/python3.5/site-packages/dropbox/dropbox.py", line 325, in request_json_string_with_retry
    timeout=timeout)
  File "/[...]/venv/lib/python3.5/site-packages/dropbox/dropbox.py", line 369, in request_json_string
    type(request_binary))
TypeError: expected request_binary as binary type, got <class 'django.core.files.base.File'>

I've already found the bug: DropBoxStorage._save receives a File or any file-like object (passed as the content argument), and then passes it straight to the self.client.files_upload method. However, DropboxBase.files_upload accepts only bytes.

I'll provide a pull request fixing both this and #301, if you don't mind.

maxmalysh added a commit to maxmalysh/django-storages that referenced this issue Aug 10, 2017
maxmalysh added a commit to maxmalysh/django-storages that referenced this issue Aug 10, 2017
maxmalysh added a commit to maxmalysh/django-storages that referenced this issue Aug 10, 2017
@jschneier
Copy link
Owner

jschneier commented Aug 10, 2017 via email

jschneier pushed a commit that referenced this issue Aug 14, 2017
* Fix .save method of the Dropbox backend (#378)

* Dropbox large file support (#301)

* Make linter happy
jschneier pushed a commit that referenced this issue Aug 14, 2017
* Fix .save method of the Dropbox backend (#378)

* Dropbox large file support (#301)

* Make linter happy
jschneier pushed a commit that referenced this issue Aug 14, 2017
* Fix .save method of the Dropbox backend (#378)

* Dropbox large file support (#301)

* Make linter happy
@lucasrcezimbra
Copy link
Contributor

Has this fix already been released? Or do you have a date forecast to release?

Thanks.

@flyalex
Copy link

flyalex commented Nov 8, 2017

@Lrcezimbra make:
pip uninstall django-storages
pip install -e 'git+https://github.com/jschneier/django-storages.git#egg=django-storages'

@lucasrcezimbra
Copy link
Contributor

@flyalex I'm using like this, thanks!

nitely pushed a commit to satellogic/django-storages that referenced this issue Jul 30, 2018
* Fix .save method of the Dropbox backend (jschneier#378)

* Dropbox large file support (jschneier#301)

* Make linter happy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants