Opened 5 years ago
Last modified 5 years ago
#32452 closed New feature
Simplify storing strings/bytes in a Storage — at Version 2
| Reported by: | Thomas Güttler | Owned by: | nobody |
|---|---|---|---|
| Component: | File uploads/storage | Version: | 3.1 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Docs: https://docs.djangoproject.com/en/3.1/topics/files/#storage-objects
path = default_storage.save('path/to/file', ContentFile(b'new content'))
Things would be bit easier, if save() would support strings/bytes directly.
This way a developer needs to type and import less code:
path = default_storage.save('path/to/file', b'new content')
path = default_storage.save('path/to/file', 'new unicode string, encoded automatically with utf-8')
Would you accept a patch to Storage.save()?
Background: I am writing a unittest which mocked away the storage calls to save() will put the data into the mock.
Then I check if the data is the way I want it.
Now it gets complicated again: I need to access the data which is inside ContentFile grrr.
This would be much easier if you could add strings/bytes to the save() directly.
Change History (2)
comment:1 by , 5 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 5 years ago
| Description: | modified (diff) |
|---|