To save strings/bytes you need to use ContentFile up to now:

path = default_storage.save('path/to/file', ContentFile(b'new content'))

Docs:  https://docs.djangoproject.com/en/3.1/topics/files/#storage-objects

Things would be bit easier, if save() would support strings/bytes directly.

This way a developer needs to type and import less code.

The implementation would be simple: Storage.save() could check with 
"isinstance()"

if the value needs to be wrapped in ContentFile.

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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/fabd4661-93b9-45f4-a47e-3ffc31abc50cn%40googlegroups.com.
  • Fea... guettli
    • ... 'Adam Johnson' via Django developers (Contributions to Django itself)
      • ... Mariusz Felisiak
      • ... guettli

Reply via email to