Skip to main content

Upload documents from the cloud to the cloud without time out error.

Project description

Cloud_resumable_upload - Upload documents from the cloud to the cloud without time out error

Detailed usage documentation is still in progress The objective of this package is to allow developpers to upload large files into cloud drives from web applications without any timeout error. Using cloud web application, backend activities are limited to 20 to 30 seconds of run time before they are close without response. In order to overcome this limitation, a possibility is to use resumable upload which allows you to send chunks of the file you wish to upload.

As of now, this package only helps developpers uploading resumable files for SharePoint. Our next objective is to develop this functionality for Google as well.

Installation

This is how you can install it on your machine:

pip install cloud_resumable_upload

Use case

You have a 20Mb file that you wish to upload to SharePoint from a web application. You are using the library o365.

#Step 1: Set up

from O365 import Account #we are using this library as a base for our package
from cloud_resumable_upload import prepare_resumable_split, upload_file_resumable #those are the two functions we will need for this use case
drive = get_sp_drive(Account, 'youraccount.sharepoint.com', 'yoursharepointsite') #in this example, we will use the main folder as the location for our upload

#Step 2: split file

file_size, partnum, chunked_files = prepare_resumable_split('yourfile.ext', 'todir', chunksize=4194304) #this function splits the file of you choice in the folder of your choice and returns information regarding the execution

#Step 3: simple loop through the chunked files

chunkrank = 1
current_bytes = 0
for i in chunked_files:
    print('chunkfile: ',i)
    print('chunkrank: ',chunkrank)
    print('current_bytes: ',current_bytes)
    if chunkrank == 1:
        current_bytes, url = upload_file_resumable(drive, i, file_size, current_bytes, 'video_demo.mp4')
    elif chunkrank < len(chunked_files):
        current_bytes, url = upload_file_resumable(drive, i, file_size, current_bytes, 'video_demo.mp4', url)
    else:
    	upload_file_resumable(drive, i, file_size, current_bytes, 'video_demo.mp4', url)
    chunkrank += 1

This can very simply be integrated in flask back end API.

List of the functions available [last update: 6/1/2020]:

prepare_resumable_split(file, todir, chunksize=4194304)

Split a file into chunks in a directory This function is spliting the file into chunks based on the "chunksize" determined in the arguments. This function returns: - file_size (int): the overall file size of the file that is needed to appropriately send a resumable file in SharePoint. - partnum (int): the number of the chunks that have been created - chunked_files (list): a list of the file names that have been created

param file: path to the file you want to upload param todir: path of the folder where you want the chunks to be temporarorily saved param chunksize: size of the chunks (in bytes)

upload_file_resumable(drive, item, file_size, current_bytes, filename, url_first=None, chunk_size=4194304)

Uploads a resumable file This function is an addon to the Library O365 in the sense that it adds the possibility for the user to create a resumable upload of a file. This resumable upload of the file is mandatory when it comes to uploading large files through a web application.

param item: path to the item you want to upload param file_size: total size of the file you want to upload param current_bytes: size of the chunk that is being uploaded param filename: name of the file param url: url with ID of the file that is temporarily saved in SharePoint param chunksize: size of the chunks (in bytes)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cloud_resumable_upload-0.2.dev0.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file cloud_resumable_upload-0.2.dev0.tar.gz.

File metadata

  • Download URL: cloud_resumable_upload-0.2.dev0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

File hashes

Hashes for cloud_resumable_upload-0.2.dev0.tar.gz
Algorithm Hash digest
SHA256 7d85a2526e969ec059aa51b3cc0355ac01ed40359d4b2bf9eadce1700fed9b08
MD5 84d54cde14a4d49c8e1ddc907054bcdb
BLAKE2b-256 f608afb2f308ac547a4ddbc87a3302618c69037f562138e05662800059ae1a31

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page