コード例 #1
0
def upload_large(file, **options):
    """ Upload large files. """
    upload_id = utils.random_public_id()
    with open(file, 'rb') as file_io:
        upload = None
        current_loc = 0
        chunk_size = options.get("chunk_size", 20000000)
        file_size = getsize(file)
        chunk = file_io.read(chunk_size)
        while (chunk):
            chunk_io = BytesIO(chunk)
            chunk_io.name = basename(file)
            range = "bytes {0}-{1}/{2}".format(current_loc,
                                               current_loc + len(chunk) - 1,
                                               file_size)
            current_loc += len(chunk)
            upload = upload_large_part(chunk_io,
                                       http_headers={
                                           "Content-Range": range,
                                           "X-Unique-Upload-Id": upload_id
                                       },
                                       **options)
            options["public_id"] = upload.get("public_id")
            chunk = file_io.read(chunk_size)
        return upload
コード例 #2
0
ファイル: uploader.py プロジェクト: juliogtz/feelkm
def upload_large(file, **options):
    """ Upload large raw files. Note that public_id should include an extension for best results. """
    with open(file, 'rb') as file_io:
        upload = upload_id = None
        index = 1
        public_id = options.get("public_id")
        chunk = file_io.read(20000000)
        while (chunk):
            chunk_io = BytesIO(chunk)
            chunk_io.name = basename(file)
            chunk = file_io.read(20000000)
            upload = upload_large_part(chunk_io, public_id=public_id,
                            upload_id=upload_id, part_number=index, final=chunk != "", **options)
            upload_id = upload.get("upload_id")
            public_id = upload.get("public_id")
            index += 1
        return upload
コード例 #3
0
def upload_large(file, **options):
    """ Upload large raw files. Note that public_id should include an extension for best results. """
    with open(file, 'rb') as file_io:
        upload = upload_id = None
        index = 1
        public_id = options.get("public_id")
        chunk = file_io.read(20000000)
        while (chunk):
            chunk_io = BytesIO(chunk)
            chunk_io.name = basename(file)
            chunk = file_io.read(20000000)
            upload = upload_large_part(chunk_io, public_id=public_id,
                            upload_id=upload_id, part_number=index, final=chunk == "", **options)
            upload_id = upload.get("upload_id")
            public_id = upload.get("public_id")
            index += 1
        return upload
コード例 #4
0
ファイル: uploader.py プロジェクト: nloadholtes/pycloudinary
def upload_large(file, **options):
    """ Upload large files. """
    upload_id = utils.random_public_id()
    with open(file, 'rb') as file_io:
        upload = None
        current_loc = 0
        chunk_size = options.get("chunk_size", 20000000)
        file_size = getsize(file)
        chunk = file_io.read(chunk_size)        
        while (chunk):
            chunk_io = BytesIO(chunk)
            chunk_io.name = basename(file)
            range = "bytes {0}-{1}/{2}".format(current_loc, current_loc + len(chunk) - 1, file_size)
            current_loc += len(chunk)
            upload = upload_large_part(chunk_io, http_headers={"Content-Range": range, "X-Unique-Upload-Id": upload_id}, **options)
            options["public_id"] = upload.get("public_id")
            chunk = file_io.read(chunk_size)
        return upload