本文整理汇总了Python中google.appengine.ext.blobstore.create_upload_url方法的典型用法代码示例。如果您正苦于以下问题:Python blobstore.create_upload_url方法的具体用法?Python blobstore.create_upload_url怎么用?Python blobstore.create_upload_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.ext.blobstore
的用法示例。
在下文中一共展示了blobstore.create_upload_url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_success
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def test_success(self):
"""Basic dispatcher request flow."""
# Create upload.
upload_data = (
"""--================1234==
Content-Type: text/plain
MIME-Version: 1.0
Content-Disposition: form-data; name="field1"; filename="stuff.txt"
value
--================1234==--""")
upload_url = blobstore.create_upload_url('/success?foo=bar')
upload, forward_environ, _ = self._run_test_success(
upload_data, upload_url)
self.assertEquals('/success', forward_environ['PATH_INFO'])
self.assertEquals('foo=bar', forward_environ['QUERY_STRING'])
self.assertEquals(
('form-data', {'filename': 'stuff.txt', 'name': 'field1'}),
cgi.parse_header(upload['content-disposition']))
示例2: test_success_with_bucket
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def test_success_with_bucket(self):
"""Basic dispatcher request flow."""
# Create upload.
upload_data = (
"""--================1234==
Content-Type: text/plain
MIME-Version: 1.0
Content-Disposition: form-data; name="field1"; filename="stuff.txt"
value
--================1234==--""")
upload_url = blobstore.create_upload_url('/success?foo=bar',
gs_bucket_name='my_test_bucket')
upload, forward_environ, forward_body = self._run_test_success(
upload_data, upload_url)
self.assertEquals('/success', forward_environ['PATH_INFO'])
self.assertEquals('foo=bar', forward_environ['QUERY_STRING'])
self.assertEquals(
('form-data', {'filename': 'stuff.txt', 'name': 'field1'}),
cgi.parse_header(upload['content-disposition']))
self.assertIn('X-AppEngine-Cloud-Storage-Object: /gs/%s' % 'my_test_bucket',
forward_body)
示例3: test_success_full_success_url
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def test_success_full_success_url(self):
"""Request flow with a success url containing protocol, host and port."""
# Create upload.
upload_data = (
"""--================1234==
Content-Type: text/plain
MIME-Version: 1.0
Content-Disposition: form-data; name="field1"; filename="stuff.txt"
value
--================1234==--""")
# The scheme, host and port should all be ignored.
upload_url = blobstore.create_upload_url(
'https://example.com:1234/success?foo=bar')
upload, forward_environ, _ = self._run_test_success(
upload_data, upload_url)
self.assertEquals('/success', forward_environ['PATH_INFO'])
self.assertEquals('foo=bar', forward_environ['QUERY_STRING'])
self.assertEquals(
('form-data', {'filename': 'stuff.txt', 'name': 'field1'}),
cgi.parse_header(upload['content-disposition']))
示例4: test_base64
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def test_base64(self):
"""Test automatic decoding of a base-64-encoded message."""
# Create upload.
upload_data = (
"""--================1234==
Content-Type: text/plain
MIME-Version: 1.0
Content-Disposition: form-data; name="field1"; filename="stuff.txt"
Content-Transfer-Encoding: base64
%s
--================1234==--""" % base64.urlsafe_b64encode('value'))
upload_url = blobstore.create_upload_url('/success')
upload, forward_environ, _ = self._run_test_success(
upload_data, upload_url)
self.assertEquals('/success', forward_environ['PATH_INFO'])
self.assertEquals(
('form-data', {'filename': 'stuff.txt', 'name': 'field1'}),
cgi.parse_header(upload['content-disposition']))
示例5: test_bad_session
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def test_bad_session(self):
"""Using a non-existant upload session causes an error."""
upload_url = blobstore.create_upload_url('/success')
# Get session key from upload url.
session_key = upload_url.split('/')[-1]
datastore.Delete(session_key)
request_path = urlparse.urlparse(upload_url)[2]
self.environ['PATH_INFO'] = request_path
status, _, response_body, forward_environ, forward_body = (
self.run_dispatcher())
self.assertEquals('404 Not Found', status)
self.assertIn('No such upload session: %s' % session_key, response_body)
# Test that it did not forward.
self.assertEquals(None, forward_environ)
self.assertEquals(None, forward_body)
示例6: test_check_line_endings
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def test_check_line_endings(self):
"""Ensure the upload message uses correct RFC-2821 line terminators."""
# Create upload.
upload_data = (
"""--================1234==
Content-Type: text/plain
MIME-Version: 1.0
Content-Disposition: form-data; name="field1"; filename="stuff.txt"
value
--================1234==--""")
upload_url = blobstore.create_upload_url('/success')
request_path = urlparse.urlparse(upload_url)[2]
self.environ['PATH_INFO'] = request_path
self.environ['CONTENT_TYPE'] = (
'multipart/form-data; boundary="================1234=="')
status, _, _, _, forward_body = self.run_dispatcher(upload_data)
self.assertEquals('200 OK', status)
forward_body = forward_body.replace('\r\n', '')
self.assertEqual(forward_body.rfind('\n'), -1)
示例7: get
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def get(self):
user = users.get_current_user()
username = user.nickname()
items = Matrix.all()
for item in items:
logging.info('item key %s blob_key %s, filename %s ', item.key.urlsafe(), item.file_key, item.filename)
length = len(items)
upload_url = blobstore.create_upload_url("/test_upload_blob")
self.response.out.write(self.template_env.get_template("blobs.html").render(
{"username": username,
"items": items,
"length": length,
"upload_url": upload_url,
"top_form_url": "test_db_datastore"}))
示例8: get
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def get(self):
user = users.get_current_user()
username = user.nickname()
items = DatasetPB.all()
# items = [result for result in results.fetch(10)]
# for item in items:
# logging.info('fn %s', item.blob_key)
length = len(items)
upload_url = blobstore.create_upload_url("/upload_blob")
# Datazz.create(u'fn1', 'ol1')
# Datazz.all()
# Datazz.create('fn1', 'ol2')
# Datazz.create('fn2', 'ol3')
# Datazz.all()
self.response.out.write(self.template_env.get_template("blobs.html").render(
{"username": username,
"items": items,
"length": length,
"upload_url": upload_url,
"top_form_url": "blobs"}))
示例9: get
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def get(self):
user = users.get_current_user()
username = user.nickname()
first = FileMetadata.getFirstKeyForUser(username)
last = FileMetadata.getLastKeyForUser(username)
q = FileMetadata.all()
q.filter("__key__ >", first)
q.filter("__key__ < ", last)
results = q.fetch(10)
items = [result for result in results]
length = len(items)
upload_url = blobstore.create_upload_url("/upload")
self.response.out.write(self.template_env.get_template("index.html").render(
{"username": username,
"items": items,
"length": length,
"upload_url": upload_url}))
示例10: get
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def get(self):
# [START gae_blobstore_upload_url]
upload_url = blobstore.create_upload_url('/upload_photo')
# [END gae_blobstore_upload_url]
# [START gae_blobstore_upload_form]
# To upload files to the blobstore, the request method must be "POST"
# and enctype must be set to "multipart/form-data".
self.response.out.write("""
<html><body>
<form action="{0}" method="POST" enctype="multipart/form-data">
Upload File: <input type="file" name="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body></html>""".format(upload_url))
# [END gae_blobstore_upload_form]
# [START gae_blobstore_upload_handler]
示例11: get
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def get(self):
user = users.get_current_user()
username = user.nickname()
first = FileMetadata.getFirstKeyForUser(username)
last = FileMetadata.getLastKeyForUser(username)
q = FileMetadata.all()
q.filter("__key__ >", first)
q.filter("__key__ < ", last)
results = q.fetch(10)
items = [result for result in results]
length = len(items)
bucket_name = app_identity.get_default_gcs_bucket_name()
upload_url = blobstore.create_upload_url("/upload",
gs_bucket_name=bucket_name)
self.response.out.write(self.template_env.get_template("index.html").render(
{"username": username,
"items": items,
"length": length,
"upload_url": upload_url}))
示例12: test_copy_headers
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def test_copy_headers(self):
"""Tests that headers are copied, except for ones that should not be."""
# Create upload.
upload_data = (
"""--================1234==
Content-Type: text/plain
MIME-Version: 1.0
Content-Disposition: form-data; name="field1"; filename="stuff.txt"
value
--================1234==--""")
upload_url = blobstore.create_upload_url('/success')
request_path = urlparse.urlparse(upload_url)[2]
self.environ['PATH_INFO'] = request_path
self.environ['CONTENT_TYPE'] = (
'multipart/form-data; boundary="================1234=="')
self.environ['HTTP_PLEASE_COPY_ME'] = 'I get copied'
self.environ['HTTP_CONTENT_TYPE'] = 'I should not be copied'
self.environ['HTTP_CONTENT_LENGTH'] = 'I should not be copied'
self.environ['HTTP_CONTENT_MD5'] = 'I should not be copied'
status, _, response_body, forward_environ, forward_body = (
self.run_dispatcher(upload_data))
self.assertEquals('200 OK', status)
self.assertEquals('Forwarded successfully.', response_body)
self.assertIn('HTTP_PLEASE_COPY_ME', forward_environ)
self.assertEquals('I get copied', forward_environ['HTTP_PLEASE_COPY_ME'])
self.assertNotIn('HTTP_CONTENT_TYPE', forward_environ)
self.assertNotIn('HTTP_CONTENT_LENGTH', forward_environ)
self.assertNotIn('HTTP_CONTENT_MD5', forward_environ)
# These ones should have been modified.
self.assertIn('CONTENT_TYPE', forward_environ)
self.assertNotEquals(
'multipart/form-data; boundary="================1234=="',
forward_environ['CONTENT_TYPE'])
self.assertIn('CONTENT_LENGTH', forward_environ)
self.assertEquals(str(len(forward_body)), forward_environ['CONTENT_LENGTH'])
示例13: test_entity_too_large
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def test_entity_too_large(self):
"""Ensure a 413 response is generated when upload size limit exceeded."""
# Create upload.
upload_data = (
"""--================1234==
Content-Type: text/plain
MIME-Version: 1.0
Content-Disposition: form-data; name="field1"; filename="stuff.txt"
Lots and Lots of Stuff
--================1234==--""")
upload_url = blobstore.create_upload_url('/success1', max_bytes_per_blob=1)
request_path = urlparse.urlparse(upload_url)[2]
self.environ['PATH_INFO'] = request_path
self.environ['CONTENT_TYPE'] = (
'multipart/form-data; boundary="================1234=="')
status, _, _, forward_environ, forward_body = (
self.run_dispatcher(upload_data))
self.assertEquals('413 Request Entity Too Large', status)
# Test that it did not forward.
self.assertEquals(None, forward_environ)
self.assertEquals(None, forward_body)
示例14: test_filename_too_long
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def test_filename_too_long(self):
"""Ensure a 400 response is generated when filename size limit exceeded."""
filename = 'a' * 500 + '.txt'
# Create upload.
upload_data = (
"""Content-Type: multipart/form-data; boundary="================1234=="
--================1234==
Content-Type: text/plain
MIME-Version: 1.0
Content-Disposition: form-data; name="field1"; filename="%s"
Lots and Lots of Stuff
--================1234==--""" % filename)
upload_url = blobstore.create_upload_url('/success1')
request_path = urlparse.urlparse(upload_url)[2]
self.environ['PATH_INFO'] = request_path
self.environ['CONTENT_TYPE'] = (
'multipart/form-data; boundary="================1234=="')
status, _, response_body, forward_environ, forward_body = (
self.run_dispatcher(upload_data))
self.assertEquals('400 Bad Request', status)
self.assertIn('The filename exceeds the maximum allowed length of 500.',
response_body)
# Test that it did not forward.
self.assertEquals(None, forward_environ)
self.assertEquals(None, forward_body)
示例15: test_content_type_too_long
# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import create_upload_url [as 别名]
def test_content_type_too_long(self):
"""Ensure a 400 response when content-type size limit exceeded."""
content_type = 'text/' + 'a' * 500
# Create upload.
upload_data = (
"""Content-Type: multipart/form-data; boundary="================1234=="
--================1234==
Content-Type: %s
MIME-Version: 1.0
Content-Disposition: form-data; name="field1"; filename="stuff.txt"
Lots and Lots of Stuff
--================1234==--""" % content_type)
upload_url = blobstore.create_upload_url('/success1')
request_path = urlparse.urlparse(upload_url)[2]
self.environ['PATH_INFO'] = request_path
self.environ['CONTENT_TYPE'] = (
'multipart/form-data; boundary="================1234=="')
status, _, response_body, forward_environ, forward_body = (
self.run_dispatcher(upload_data))
self.assertEquals('400 Bad Request', status)
self.assertIn('The Content-Type exceeds the maximum allowed length of 500.',
response_body)
# Test that it did not forward.
self.assertEquals(None, forward_environ)
self.assertEquals(None, forward_body)