示例#1
0
    def from_dict(cls, data, bucket):
        """Construct a file wrapper from a dictionary."""
        file_args = dict(
            id=data['file_id'],
            storage_class=data.get('storage_class'),
            size=data.get('size'),
            checksum=data.get('checksum'),
        )
        if 'uri' in data:
            file_args['uri'] = data['uri']

        fi = FileInstance(**file_args)
        obj = ObjectVersion(
            version_id=data['version_id'],
            key=data['key'],
            file_id=data['file_id'],
            _mimetype=data['mimetype'],
            is_head=True,
            bucket=bucket,
            bucket_id=data.get('bucket_id', bucket.id),
        )
        return cls(object_model=obj, file_model=fi)