[Django] #18899: FileSystemStorage.save should support any file-like objects

9 views
Skip to first unread message

Django

unread,
Sep 3, 2012, 8:07:35 AM9/3/12
to django-...@googlegroups.com
#18899: FileSystemStorage.save should support any file-like objects
--------------------------------------+--------------------
Reporter: vzima | Owner: nobody
Type: Uncategorized | Status: new
Component: File uploads/storage | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
I propose generic support of `FileSystemStorage.save()`, so `content`
argument can be any object with `read([size])` method.

I see no reason why `FileSystemStorage` does not support regular file-like
objects. IT is common practise to support any file-like objects in python
libraries, where file-like object is an argument.

Blocker of this is `content.chunks()` call which itself is nothing else
then generator over `file.read(chunk_size)`. Storage itself could easily
call `content.read(chunk_size)` directly which grants support to various
file-like objects.

Calls like this are just weird:
{{{
#!python
storage.save(target, File(open(filename)))
}}}
The `File` objects is here only because it has `chunks()` method required
by `FileSystemStorage.save()` call.

I have seen #8204 but I do not require anything so specific. It is just
painful, when you want to use storage for anything else than file from
query or form.

--
Ticket URL: <https://code.djangoproject.com/ticket/18899>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 7, 2012, 4:59:42 PM11/7/12
to django-...@googlegroups.com
#18899: FileSystemStorage.save should support any file-like objects
--------------------------------------+------------------------------------
Reporter: vzima | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: File uploads/storage | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* needs_docs: => 0
* type: Uncategorized => Cleanup/optimization
* needs_tests: => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/18899#comment:1>

Django

unread,
Nov 8, 2012, 3:31:20 AM11/8/12
to django-...@googlegroups.com
#18899: FileSystemStorage.save should support any file-like objects
--------------------------------------+------------------------------------
Reporter: vzima | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: File uploads/storage | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by claudep):

In #15644, we added support for file-like objects to the File wrapper. Do
you think it is still too much to call `storage.save(target, File(<file-
like-object>))`?

--
Ticket URL: <https://code.djangoproject.com/ticket/18899#comment:2>

Django

unread,
Nov 9, 2012, 4:09:34 AM11/9/12
to django-...@googlegroups.com
#18899: FileSystemStorage.save should support any file-like objects
--------------------------------------+------------------------------------
Reporter: vzima | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: File uploads/storage | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by vzima):

Replying to [comment:2 claudep]:


> In #15644, we added support for file-like objects to the File wrapper.

Do you think it is still too much to call `storage.save(target, File
(<file-like-object>))`?
Yes. It is seems fairly excessive - you make `File` object from `file`
object - only to provide `chunks()` method. Also this is not a solution
for other file-like objects, e.g. `StringIO`.

--
Ticket URL: <https://code.djangoproject.com/ticket/18899#comment:3>

Django

unread,
Nov 10, 2012, 6:47:23 AM11/10/12
to django-...@googlegroups.com
#18899: FileSystemStorage.save should support any file-like objects
--------------------------------------+------------------------------------
Reporter: vzima | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: File uploads/storage | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by claudep):

Wrapping `StringIO` in a `File` object should work. Report it as a
separate ticket if you can show that it does not.

Maybe the simplest fix would be to wrap `content` in a `File` object if it
has no chunks method. This would preserve compatibility in the case
someone passes a custom `content` instance (which might implement chunks
in a non-standard way).

--
Ticket URL: <https://code.djangoproject.com/ticket/18899#comment:4>

Django

unread,
Feb 23, 2013, 7:12:40 AM2/23/13
to django-...@googlegroups.com
#18899: FileSystemStorage.save should support any file-like objects
--------------------------------------+------------------------------------
Reporter: vzima | Owner: biern
Type: Cleanup/optimization | Status: assigned

Component: File uploads/storage | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by biern):

* status: new => assigned
* owner: nobody => biern


--
Ticket URL: <https://code.djangoproject.com/ticket/18899#comment:5>

Django

unread,
Feb 23, 2013, 10:54:29 AM2/23/13
to django-...@googlegroups.com
#18899: FileSystemStorage.save should support any file-like objects
--------------------------------------+------------------------------------
Reporter: vzima | Owner: biern
Type: Cleanup/optimization | Status: assigned
Component: File uploads/storage | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by biern):

* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/775

--
Ticket URL: <https://code.djangoproject.com/ticket/18899#comment:6>

Django

unread,
Feb 23, 2013, 10:58:54 AM2/23/13
to django-...@googlegroups.com
#18899: FileSystemStorage.save should support any file-like objects
-------------------------------------+-------------------------------------
Reporter: vzima | Owner: biern
Type: | Status: assigned
Cleanup/optimization | Version: 1.4
Component: File | Resolution:
uploads/storage | Triage Stage: Ready for
Severity: Normal | checkin
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by gszczepanczyk):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/18899#comment:7>

Django

unread,
Feb 23, 2013, 11:05:04 AM2/23/13
to django-...@googlegroups.com
#18899: FileSystemStorage.save should support any file-like objects
-------------------------------------+-------------------------------------
Reporter: vzima | Owner: biern
Type: | Status: closed
Cleanup/optimization | Version: 1.4
Component: File | Resolution: fixed

uploads/storage | Triage Stage: Ready for
Severity: Normal | checkin
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Honza Král <Honza.Kral@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"129d2e8f85b1e80f10ec967b72ba0af9b239019f"]:
{{{
#!CommitTicketReference repository=""
revision="129d2e8f85b1e80f10ec967b72ba0af9b239019f"
Merge pull request #775 from HiddenData/ticket-18899

Fixed #18899 -- FileSystemStorage.save should support any file-like
objects
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/18899#comment:8>

Django

unread,
Aug 30, 2016, 9:41:21 PM8/30/16
to django-...@googlegroups.com
#18899: FileSystemStorage.save should support any file-like objects
-------------------------------------+-------------------------------------
Reporter: vzima | Owner: biern
Type: | Status: closed
Cleanup/optimization |
Component: File | Version: 1.4
uploads/storage |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"3f16e4df494dc9143d110b886c8e8608f9d2b584" 3f16e4df]:
{{{
#!CommitTicketReference repository=""
revision="3f16e4df494dc9143d110b886c8e8608f9d2b584"
Fixed #27145 -- Updated Storage.save() docs for refs #18899.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/18899#comment:9>

Django

unread,
Aug 30, 2016, 9:41:40 PM8/30/16
to django-...@googlegroups.com
#18899: FileSystemStorage.save should support any file-like objects
-------------------------------------+-------------------------------------
Reporter: vzima | Owner: biern
Type: | Status: closed
Cleanup/optimization |
Component: File | Version: 1.4
uploads/storage |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"f79dce16bc8b326e1ab61a71f8e841495c52c6ff" f79dce16]:
{{{
#!CommitTicketReference repository=""
revision="f79dce16bc8b326e1ab61a71f8e841495c52c6ff"
[1.10.x] Fixed #27145 -- Updated Storage.save() docs for refs #18899.

Backport of 3f16e4df494dc9143d110b886c8e8608f9d2b584 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/18899#comment:10>

Reply all
Reply to author
Forward
0 new messages