﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26495	Saving StringIO using custom storage class may result in empty content written to file	Maxim Novikov	nobody	"https://github.com/django/django/blob/master/django/core/files/storage.py#L50
{{{
#!python
class Storage(object):

    def save(self, name, content, max_length=None):
        ...
        if not hasattr(content, 'chunks'):
            content = File(content)
}}}
For example if custom storage uses requests with post query and we are saving StringIO object.
{{{
#!python
from StringIO import StringIO

from django.core.files.storage import Storage
import requests

class CustomStorage(Storage):
    def _save(self, name, content, max_length=None):
          requests.post('http://testhost.org/upload', data=content)
custom_storage = CustomStorage()
custom_storage.save('new_name', StringIO('content'))
}}}
But it will result in empty upload as bool(content) is False.
Possibly better to pass a name to File object. To ensure bool(content) is True
{{{
#!python
    if not hasattr(content, 'chunks'):
        content = File(content, name=name)
}}}"	Cleanup/optimization	closed	File uploads/storage	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
