Opened 15 years ago
Closed 11 years ago
#8501 closed New feature (duplicate)
file storage should allow saving of basic file-like objects
Reported by: | Owned by: | anonymous | |
---|---|---|---|
Component: | File uploads/storage | Version: | dev |
Severity: | Normal | Keywords: | urllib, file |
Cc: | kmike84@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
It is not possible to save file opened by urllib2.urlopen into field of a model.
When trying to do that following way:
f = File(urlopen("http://something.com/somefile.ext").fp)
MODEL.FIELD.save("name.ext", f, save=False)
Django throws AttributeError: '_fileobject' object has no attribute 'seek'
Probeably django\core\files\base.py on line checks if class has attribute seek, but it is being definied at line 125 even when constructor gets an object that does not have such attribute (like urllib2.addinfourl.fp which is socket._fileobject).
Attachments (1)
Change History (9)
comment:1 Changed 15 years ago by
milestone: | → post-1.0 |
---|---|
Owner: | changed from nobody to anonymous |
Status: | new → assigned |
Changed 15 years ago by
Attachment: | 8501v1.diff added |
---|
comment:2 Changed 15 years ago by
Has patch: | set |
---|---|
Needs documentation: | set |
Status: | assigned → new |
comment:3 Changed 15 years ago by
Interesting. It seems this is more useful than just for urlopen - it allows saving file objects (and stringio streams) directly too. In fact, I'd write urlopen off as a side-effect and rejigg the patch tests to just use open()
comment:4 Changed 15 years ago by
Patch needs improvement: | set |
---|---|
Summary: | It is not possible to save file opened by urllib2.urlopen → file storage should allow saving of basic file-like objects |
Triage Stage: | Unreviewed → Accepted |
comment:6 Changed 13 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I believe using ContentFile already handles this case:
source:django/trunk/django/core/files/base.py
Feel free to reopen if not.
comment:7 Changed 12 years ago by
Cc: | kmike84@… added |
---|---|
Easy pickings: | unset |
Resolution: | wontfix |
Severity: | → Normal |
Status: | closed → reopened |
Type: | → New feature |
UI/UX: | unset |
I think ContentFile doesn't fully cover this case because it needs a whole file loaded to memory and it should be possible to avoid this.
comment:8 Changed 11 years ago by
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
This has been fixed via duplicate ticket #15644.
Patch 8501v1.diff supports passing the result of a urlopen as the content parameter for the save method of FileField and ImageField. Here's the included testing code: