def create_upload_url(success_path,
                      _make_sync_call=None,
                      max_bytes_per_blob=None,
                      max_bytes_total=None):
    """Create upload URL for POST form.

  Args:
    success_path: Path within application to call when POST is successful
      and upload is complete.
    _make_sync_call: Used for dependency injection in tests.
    max_bytes_per_blob: The maximum size in bytes that any one blob in the
      upload can be or None for no maximum size.
    max_bytes_total: The maximum size in bytes that the aggregate sizes of all
      of the blobs in the upload can be or None for no maximum size.

  Raises:
    TypeError: If max_bytes_per_blob or max_bytes_total are not integral types.
    ValueError: If max_bytes_per_blob or max_bytes_total are not
      positive values.
  """
    request = blobstore_service_pb.CreateUploadURLRequest()
    response = blobstore_service_pb.CreateUploadURLResponse()
    request.set_success_path(success_path)

    if _make_sync_call is not None:
        if not callable(_make_sync_call):
            raise TypeError('_make_sync_call must be callable')
    else:
        _make_sync_call = apiproxy_stub_map.MakeSyncCall

    if max_bytes_per_blob is not None:
        if not isinstance(max_bytes_per_blob, (int, long)):
            raise TypeError('max_bytes_per_blob must be integer.')
        if max_bytes_per_blob < 1:
            raise ValueError('max_bytes_per_blob must be positive.')
        request.set_max_upload_size_per_blob_bytes(max_bytes_per_blob)

    if max_bytes_total is not None:
        if not isinstance(max_bytes_total, (int, long)):
            raise TypeError('max_bytes_total must be integer.')
        if max_bytes_total < 1:
            raise ValueError('max_bytes_total must be positive.')
        request.set_max_upload_size_bytes(max_bytes_total)

    if (request.has_max_upload_size_bytes()
            and request.has_max_upload_size_per_blob_bytes()):
        if (request.max_upload_size_bytes() <
                request.max_upload_size_per_blob_bytes()):
            raise ValueError('max_bytes_total can not be less'
                             ' than max_upload_size_per_blob_bytes')

    try:
        _make_sync_call('blobstore', 'CreateUploadURL', request, response)
    except apiproxy_errors.ApplicationError, e:
        raise _ToBlobstoreError(e)
Esempio n. 2
0
def create_upload_url_async(success_path,
                            max_bytes_per_blob=None,
                            max_bytes_total=None,
                            rpc=None):
    """Create upload URL for POST form -- async version.

  Args:
    success_path: Path within application to call when POST is successful
      and upload is complete.
    max_bytes_per_blob: The maximum size in bytes that any one blob in the
      upload can be or None for no maximum size.
    max_bytes_total: The maximum size in bytes that the aggregate sizes of all
      of the blobs in the upload can be or None for no maximum size.
    rpc: Optional UserRPC object.

  Returns:
    A UserRPC whose result will be the upload URL.

  Raises:
    TypeError: If max_bytes_per_blob or max_bytes_total are not integral types.
    ValueError: If max_bytes_per_blob or max_bytes_total are not
      positive values.
  """
    request = blobstore_service_pb.CreateUploadURLRequest()
    response = blobstore_service_pb.CreateUploadURLResponse()
    request.set_success_path(success_path)

    if max_bytes_per_blob is not None:
        if not isinstance(max_bytes_per_blob, (int, long)):
            raise TypeError('max_bytes_per_blob must be integer.')
        if max_bytes_per_blob < 1:
            raise ValueError('max_bytes_per_blob must be positive.')
        request.set_max_upload_size_per_blob_bytes(max_bytes_per_blob)

    if max_bytes_total is not None:
        if not isinstance(max_bytes_total, (int, long)):
            raise TypeError('max_bytes_total must be integer.')
        if max_bytes_total < 1:
            raise ValueError('max_bytes_total must be positive.')
        request.set_max_upload_size_bytes(max_bytes_total)

    if (request.has_max_upload_size_bytes()
            and request.has_max_upload_size_per_blob_bytes()):
        if (request.max_upload_size_bytes() <
                request.max_upload_size_per_blob_bytes()):
            raise ValueError('max_bytes_total can not be less'
                             ' than max_upload_size_per_blob_bytes')

    return _make_async_call(rpc, 'CreateUploadURL', request, response,
                            _get_result_hook, lambda rpc: rpc.response.url())
Esempio n. 3
0
def create_upload_url(success_path,
                      _make_sync_call=apiproxy_stub_map.MakeSyncCall):
    """Create upload URL for POST form.

  Args:
    success_path: Path within application to call when POST is successful
      and upload is complete.
    _make_sync_call: Used for dependency injection in tests.
  """
    request = blobstore_service_pb.CreateUploadURLRequest()
    response = blobstore_service_pb.CreateUploadURLResponse()
    request.set_success_path(success_path)
    try:
        _make_sync_call('blobstore', 'CreateUploadURL', request, response)
    except apiproxy_errors.ApplicationError, e:
        raise _ToBlobstoreError(e)
Esempio n. 4
0
def create_upload_url_async(success_path,
                            max_bytes_per_blob=None,
                            max_bytes_total=None,
                            rpc=None,
                            gs_bucket_name=None):
    """Create upload URL for POST form -- async version.

  Args:
    success_path: Path within application to call when POST is successful
      and upload is complete.
    max_bytes_per_blob: The maximum size in bytes that any one blob in the
      upload can be or None for no maximum size.
    max_bytes_total: The maximum size in bytes that the aggregate sizes of all
      of the blobs in the upload can be or None for no maximum size.
    rpc: Optional UserRPC object.
    gs_bucket_name: The Google Storage bucket name that the blobs should be
      uploaded to. The application's service account must have the correct
      permissions to write to this bucket. The bucket name may be of the foramt
      'bucket/path/', in which case the included path will be prepended to the
      uploaded object name.

  Returns:
    A UserRPC whose result will be the upload URL.

  Raises:
    TypeError: If max_bytes_per_blob or max_bytes_total are not integral types.
    ValueError: If max_bytes_per_blob or max_bytes_total are not
      positive values.
  """
    request = blobstore_service_pb.CreateUploadURLRequest()
    response = blobstore_service_pb.CreateUploadURLResponse()
    request.set_success_path(success_path)

    if max_bytes_per_blob is not None:
        if not isinstance(max_bytes_per_blob, (int, long)):
            raise TypeError('max_bytes_per_blob must be integer.')
        if max_bytes_per_blob < 1:
            raise ValueError('max_bytes_per_blob must be positive.')
        request.set_max_upload_size_per_blob_bytes(max_bytes_per_blob)

    if max_bytes_total is not None:
        if not isinstance(max_bytes_total, (int, long)):
            raise TypeError('max_bytes_total must be integer.')
        if max_bytes_total < 1:
            raise ValueError('max_bytes_total must be positive.')
        request.set_max_upload_size_bytes(max_bytes_total)

    if (request.has_max_upload_size_bytes()
            and request.has_max_upload_size_per_blob_bytes()):
        if (request.max_upload_size_bytes() <
                request.max_upload_size_per_blob_bytes()):
            raise ValueError('max_bytes_total can not be less'
                             ' than max_upload_size_per_blob_bytes')

    if gs_bucket_name is not None:
        if not isinstance(gs_bucket_name, basestring):
            raise TypeError('gs_bucket_name must be a string.')
        request.set_gs_bucket_name(gs_bucket_name)

    return _make_async_call(rpc, 'CreateUploadURL', request, response,
                            _get_result_hook, lambda rpc: rpc.response.url())