hbp_service_client/storage_service/api.py
def upload_file_content(self, file_id, etag=None, source=None, content=None):
        '''Upload a file content. The file entity must already exist.

        If an ETag is provided the file stored on the server is verified
        against it. If it does not match, StorageException is raised.
        This means the client needs to update its knowledge of the resource
        before attempting to update again. This can be used for optimistic
        concurrency control.

        Args:
            file_id (str): The UUID of the file whose content is written.
            etag (str): The etag to match the contents against.
            source (str): The path of the local file whose content to be uploaded.
            content (str): A string of the content to be uploaded.

        Note:
            ETags should be enclosed in double quotes::

                my_etag = '"71e1ed9ee52e565a56aec66bc648a32c"'

        Returns:
            The ETag of the file upload::

                '"71e1ed9ee52e565a56aec66bc648a32c"'

        Raises:
            IOError: The source cannot be opened.
            StorageArgumentException: Invalid arguments
            StorageForbiddenException: Server response code 403
            StorageNotFoundException: Server response code 404
            StorageException: other 400-600 error codes
        '''
        if not is_valid_uuid(file_id):
            raise StorageArgumentException(
                'Invalid UUID for file_id: {0}'.format(file_id))

        if not (source or content) or (source and content):
            raise StorageArgumentException('Either one of source file or content '
                                           'has to be provided.')

        resp = self._authenticated_request \
            .to_endpoint('file/{}/content/upload/'.format(file_id)) \
            .with_body(content or open(source, 'rb')) \
            .with_headers({'If-Match': etag} if etag else {}) \
            .post()

        if 'ETag' not in resp.headers:
            raise StorageException('No ETag received from the service after the upload')

        return resp.headers['ETag']
def upload_file_content(self, file_id, etag=None, source=None, content=None):
        '''Upload a file content. The file entity must already exist.

        If an ETag is provided the file stored on the server is verified
        against it. If it does not match, StorageException is raised.
        This means the client needs to update its knowledge of the resource
        before attempting to update again. This can be used for optimistic
        concurrency control.

        Args:
            file_id (str): The UUID of the file whose content is written.
            etag (str): The etag to match the contents against.
            source (str): The path of the local file whose content to be uploaded.
            content (str): A string of the content to be uploaded.

        Note:
            ETags should be enclosed in double quotes::

                my_etag = '"71e1ed9ee52e565a56aec66bc648a32c"'

        Returns:
            The ETag of the file upload::

                '"71e1ed9ee52e565a56aec66bc648a32c"'

        Raises:
            IOError: The source cannot be opened.
            StorageArgumentException: Invalid arguments
            StorageForbiddenException: Server response code 403
            StorageNotFoundException: Server response code 404
            StorageException: other 400-600 error codes
        '''
        if not is_valid_uuid(file_id):
            raise StorageArgumentException(
                'Invalid UUID for file_id: {0}'.format(file_id))

        if not (source or content) or (source and content):
            raise StorageArgumentException('Either one of source file or content '
                                           'has to be provided.')

        resp = self._authenticated_request \
            .to_endpoint('file/{}/content/upload/'.format(file_id)) \
            .with_body(content or open(source, 'rb')) \
            .with_headers({'If-Match': etag} if etag else {}) \
            .post()

        if 'ETag' not in resp.headers:
            raise StorageException('No ETag received from the service after the upload')

        return resp.headers['ETag']
def upload_file_content ( self , file_id , etag = None , source = None , content = None ) : if not is_valid_uuid ( file_id ) : raise StorageArgumentException ( 'Invalid UUID for file_id: {0}' . format ( file_id ) ) if not ( source or content ) or ( source and content ) : raise StorageArgumentException ( 'Either one of source file or content ' 'has to be provided.' ) resp = self . _authenticated_request . to_endpoint ( 'file/{}/content/upload/' . format ( file_id ) ) . with_body ( content or open ( source , 'rb' ) ) . with_headers ( { 'If-Match' : etag } if etag else { } ) . post ( ) if 'ETag' not in resp . headers : raise StorageException ( 'No ETag received from the service after the upload' ) return resp . headers [ 'ETag' ]
Upload a file content. The file entity must already exist.

        If an ETag is provided the file stored on the server is verified
        against it. If it does not match, StorageException is raised.
        This means the client needs to update its knowledge of the resource
        before attempting to update again. This can be used for optimistic
        concurrency control.

        Args:
            file_id (str): The UUID of the file whose content is written.
            etag (str): The etag to match the contents against.
            source (str): The path of the local file whose content to be uploaded.
            content (str): A string of the content to be uploaded.

        Note:
            ETags should be enclosed in double quotes::

                my_etag = '"71e1ed9ee52e565a56aec66bc648a32c"'

        Returns:
            The ETag of the file upload::

                '"71e1ed9ee52e565a56aec66bc648a32c"'

        Raises:
            IOError: The source cannot be opened.
            StorageArgumentException: Invalid arguments
            StorageForbiddenException: Server response code 403
            StorageNotFoundException: Server response code 404
            StorageException: other 400-600 error codes
Upload a file content . The file entity must already exist .