Storage should reset file's cursor after saving
|Reported by:||Julien Phalip||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I had some trouble finding the cause of that problem. Basically, I was trying to save an uploaded image and then manipulate that image with PIL. But the following didn't work:
from PIL import Image storage.save('/images/image.gif', uploaded_file) # Save the original uploaded_image = Image.open(uploaded_file) ...
After debugging PIL I realised that it assumes the given file starts at position 0. Therefore, the following works:
from PIL import Image storage.save('/images/image.gif', uploaded_file) # Save the original uploaded_file.seek(0) # >> REWIND FILE << uploaded_image = Image.open(uploaded_file) ...
I think it would be good practice to automatically rewind the file after it's been saved, so that other tools can process the file without having to rewind it manually. That would feel more logical from an outside perspective.
Change History (10)
comment:2 Changed 9 years ago by
|Summary:||Storage should rewind files after saving → Storage should reset file's cursor after saving|
comment:3 Changed 9 years ago by
|Component:||Uncategorized → File uploads/storage|
|Triage Stage:||Unreviewed → Accepted|