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

FileStorage.save() does not support pathlib #1653

Closed
manlix opened this issue Oct 17, 2019 · 0 comments · Fixed by #1654
Closed

FileStorage.save() does not support pathlib #1653

manlix opened this issue Oct 17, 2019 · 0 comments · Fixed by #1654
Milestone

Comments

@manlix
Copy link
Contributor

@manlix manlix commented Oct 17, 2019

Description

I expected save uploaded file to pathlib object.

Code

from pathlib import Path

# ...

def path_to_save(document_id):
    return Path(myproject.config.DocumentProcessing.save_to(document_id))

# ...

request.files['document'].save(path_to_save(document_id))

# ...

Actual Behavior

Uploaded file document did not save to filesystem:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/lib/myproject/myproject/website/blueprints/document.py", line 23, in create_document
    result = schemas.DocumentSchema().dump(utils.uploaded_document())
  File "/var/lib/myproject/myproject/website/utils.py", line 39, in uploaded_document
    request.files['document'].save(path_to_save(document_id)) 
  File "/usr/local/lib/python3.7/site-packages/werkzeug/datastructures.py", line 2803, in save
    copyfileobj(self.stream, dst, buffer_size)
  File "/usr/local/lib/python3.7/shutil.py", line 82, in copyfileobj
    fdst.write(buf)
AttributeError: 'PosixPath' object has no attribute 'write'

Expected Behavior

Uploaded file document saved to filesystem.

Versions

Python: 3.7.4
Werkzeug: 0.16.0

@davidism davidism changed the title werkzeug.datastructures.FileStorage.save() does not support pathlib FileStorage.save() does not support pathlib Oct 17, 2019
@davidism davidism added this to the 1.0.0 milestone Oct 18, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants