diff --git a/mediagoblin/storage/cloudfiles.py b/mediagoblin/storage/cloudfiles.py
index 532e5ba..61665ea 100644
a
|
b
|
class CloudFilesStorageObjectWrapper():
|
193 | 193 | return self.storage_object.read(*args, **kwargs) |
194 | 194 | |
195 | 195 | def write(self, data, *args, **kwargs): |
196 | | """ |
197 | | write data to the cloudfiles storage object |
198 | | |
199 | | The original motivation for this wrapper is to ensure |
200 | | that buffered writing to a cloudfiles storage object does not overwrite |
201 | | any preexisting data. |
202 | | |
203 | | Currently this method does not support any write modes except "append". |
204 | | However if we should need it it would be easy implement. |
205 | | """ |
206 | | _log.warn( |
207 | | '{0}.write() has bad performance! Use .send instead for now'\ |
208 | | .format(self.__class__.__name__)) |
209 | | |
210 | | if self.storage_object.size and type(data) == str: |
211 | | _log.debug('{0} is > 0 in size, appending data'.format( |
212 | | self.storage_object.name)) |
213 | | data = self.read() + data |
214 | | |
215 | | _log.debug('Writing {0}'.format( |
216 | | self.storage_object.name)) |
217 | 196 | self.storage_object.write(data, *args, **kwargs) |
218 | 197 | |
219 | 198 | def send(self, *args, **kw): |
diff --git a/mediagoblin/storage/filestorage.py b/mediagoblin/storage/filestorage.py
index f989539..89f4327 100644
a
|
b
|
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
| 17 | import io |
17 | 18 | import os |
18 | 19 | import shutil |
19 | 20 | |
… |
… |
from mediagoblin.storage import (
|
24 | 25 | clean_listy_filepath, |
25 | 26 | NoWebServing) |
26 | 27 | |
| 28 | class FileObjectAwareFile(io.FileIO): |
| 29 | def write(self, data): |
| 30 | if hasattr(data, 'read'): |
| 31 | # We can call data.read(). It means that the data is a file-like |
| 32 | # object, which should be saved RAM-friendly way |
| 33 | shutil.copyfileobj(data, self) |
| 34 | else: |
| 35 | super(FileObjectAwareFile, self).write(data) |
| 36 | |
27 | 37 | |
28 | 38 | class BasicFileStorage(StorageInterface): |
29 | 39 | """ |
… |
… |
class BasicFileStorage(StorageInterface):
|
60 | 70 | os.makedirs(directory) |
61 | 71 | |
62 | 72 | # Grab and return the file in the mode specified |
63 | | return open(self._resolve_filepath(filepath), mode) |
| 73 | return FileObjectAwareFile(self._resolve_filepath(filepath), mode) |
64 | 74 | |
65 | 75 | def delete_file(self, filepath): |
66 | 76 | """Delete file at filepath |
diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py
index 541447e..a0e1cf9 100644
a
|
b
|
def submit_media(mg_app, user, submitted_file, filename,
|
157 | 157 | queue_file = prepare_queue_task(mg_app, entry, filename) |
158 | 158 | |
159 | 159 | with queue_file: |
160 | | queue_file.write(submitted_file.read()) |
| 160 | queue_file.write(submitted_file) |
161 | 161 | |
162 | 162 | # Get file size and round to 2 decimal places |
163 | 163 | file_size = mg_app.queue_store.get_file_size( |