當前位置: 首頁>>代碼示例>>Python>>正文


Python blobstore.create_upload_url方法代碼示例

本文整理匯總了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'])) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:24,代碼來源:blob_upload_test.py

示例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) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:27,代碼來源:blob_upload_test.py

示例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'])) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:26,代碼來源:blob_upload_test.py

示例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'])) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:24,代碼來源:blob_upload_test.py

示例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) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:20,代碼來源:blob_upload_test.py

示例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) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:26,代碼來源:blob_upload_test.py

示例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"})) 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:18,代碼來源:test_db_datastore.py

示例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"})) 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:25,代碼來源:blobs.py

示例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})) 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:24,代碼來源:mr_main.py

示例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] 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:20,代碼來源:main.py

示例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})) 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-mapreduce,代碼行數:26,代碼來源:main.py

示例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']) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:42,代碼來源:blob_upload_test.py

示例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) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:28,代碼來源:blob_upload_test.py

示例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) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:33,代碼來源:blob_upload_test.py

示例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) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:33,代碼來源:blob_upload_test.py


注:本文中的google.appengine.ext.blobstore.create_upload_url方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。