def create(cls, bucket, key, size, chunk_size):
        """Create a new object in a bucket."""
        bucket = as_bucket(bucket)

        if bucket.locked:
            raise BucketLockedError()

        # Validate chunk size.
        if not cls.is_valid_chunksize(chunk_size):
            raise MultipartInvalidChunkSize()

        # Validate max theoretical size.
        if not cls.is_valid_size(size, chunk_size):
            raise MultipartInvalidSize()

        # Validate max bucket size.
        bucket_limit = bucket.size_limit
        if bucket_limit and size > bucket_limit:
            desc = 'File size limit exceeded.' \
                if isinstance(bucket_limit, int) else bucket_limit.reason
            raise FileSizeError(description=desc)

        with db.session.begin_nested():
            file_ = FileInstance.create()
            file_.size = size
            obj = cls(
                upload_id=uuid.uuid4(),
                bucket=bucket,
                key=key,
                chunk_size=chunk_size,
                size=size,
                completed=False,
                file=file_,
            )
            bucket.size += size
            db.session.add(obj)
        file_.init_contents(
            size=size,
            default_location=bucket.location.uri,
            default_storage_class=bucket.default_storage_class,
        )
        return obj
def create ( cls , bucket , key , size , chunk_size ) : bucket = as_bucket ( bucket ) if bucket . locked : raise BucketLockedError ( ) if not cls . is_valid_chunksize ( chunk_size ) : raise MultipartInvalidChunkSize ( ) if not cls . is_valid_size ( size , chunk_size ) : raise MultipartInvalidSize ( ) bucket_limit = bucket . size_limit if bucket_limit and size > bucket_limit : desc = 'File size limit exceeded.' if isinstance ( bucket_limit , int ) else bucket_limit . reason raise FileSizeError ( description = desc ) with db . session . begin_nested ( ) : file_ = FileInstance . create ( ) file_ . size = size obj = cls ( upload_id = uuid . uuid4 ( ) , bucket = bucket , key = key , chunk_size = chunk_size , size = size , completed = False , file = file_ , ) bucket . size += size db . session . add ( obj ) file_ . init_contents ( size = size , default_location = bucket . location . uri , default_storage_class = bucket . default_storage_class , ) return obj
Create a new object in a bucket.