Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3705)

Unified Diff: app/handlers/cloud_storage.py

Issue 1031663002: Increase maximum file upload to 100MB, use cloudstorage python library (Closed) Base URL: https://github.com/dart-lang/pub-dartlang.git@master
Patch Set: Add deprecation comment to old cloud_storage.py:open() function Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « app/cloudstorage ('k') | app/models/package.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/handlers/cloud_storage.py
diff --git a/app/handlers/cloud_storage.py b/app/handlers/cloud_storage.py
index 5ca93213d8dbaaac4bd76fb4fb2457542fb59858..6b288f6c999d7317da6be145c9405a87da5e9f00 100644
--- a/app/handlers/cloud_storage.py
+++ b/app/handlers/cloud_storage.py
@@ -22,6 +22,8 @@ from google.appengine.api import urlfetch
from models.private_key import PrivateKey
+import cloudstorage
+
# The Google Cloud Storage bucket for this app
_BUCKET = "pub.dartlang.org"
@@ -214,9 +216,16 @@ def delete_object(obj):
files.delete(_appengine_object_path(obj))
def open(obj):
- """Opens an object in cloud storage."""
+ """Opens an object in cloud storage.
+
+ DEPRECATED: For larger files, please consider using `open_with_gcs()`.
+ """
return files.open(_appengine_object_path(obj), 'r')
+def open_with_gcs(obj):
+ """Opens an object in cloud storage with the GCS library."""
+ return cloudstorage.open(_gcs_appengine_object_path(obj), 'r')
+
def read(obj):
"""Consumes and returns all data in an object in cloud storage.
@@ -226,7 +235,7 @@ def read(obj):
This can be necessary since many operations on the file object itself
require a network round trip."""
- with open(obj) as f:
+ with open_with_gcs(obj) as f:
io = StringIO()
data = f.read(_CHUNK_SIZE)
while data:
@@ -252,6 +261,10 @@ def _appengine_object_path(obj):
"""Returns the path for an object for use with the AppEngine APIs."""
return '/gs/' + _object_path(obj)
+def _gcs_appengine_object_path(obj):
+ """Returns the path for an object for use with the GCS APIs."""
+ return '/' + _object_path(obj)
+
def _iso8601(secs):
"""Returns the ISO8601 representation of the given time.
« no previous file with comments | « app/cloudstorage ('k') | app/models/package.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698