Jannis Leidel avatar Jannis Leidel committed fd89bca

Fix uploading with a file of the Google Storage backend (multipart upload isn't supported there).

Comments (0)

Files changed (1)


+    from cStringIO import StringIO
+except ImportError:
+    from StringIO import StringIO  # noqa
 from django.core.exceptions import ImproperlyConfigured
 from storages.backends.s3boto import S3BotoStorage, S3BotoStorageFile, setting
 class GSBotoStorageFile(S3BotoStorageFile):
-    buffer_size = setting('GS_FILE_BUFFER_SIZE', 5242880)
+    def write(self, content):
+        if 'w' not in self._mode:
+            raise AttributeError("File was not opened in write mode.")
+        self.file = StringIO(content)
+        self._is_dirty = True
+    def close(self):
+        if self._is_dirty:
+            provider = self.key.bucket.connection.provider
+            upload_headers = {provider.acl_header: self._storage.default_acl}
+            upload_headers.update(self._storage.headers)
+            self._storage._save_content(self.key, self.file, upload_headers)
+        self.key.close()
 class GSBotoStorage(S3BotoStorage):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.