vimeo / vimeo.py

Official Python library for the Vimeo API.
https://developer.vimeo.com
Apache License 2.0
210 stars 85 forks source link

Tus upload taking incredibly long time #157

Open typefox09 opened 4 years ago

typefox09 commented 4 years ago

Hi, i am experiencing a really long wait time once performing a Tus upload with the api. For a 280mb video (created on my phone) it takes a total of 2 mins and 28 seconds. This is with the chunk size set to 130 1024 1024 also. I have tried decreasing the chunk size however then it starts taking even longer. What's the best way to have this run in the background so a user can continue browsing?

My code (helper function that takes the uploaded video from form as parameter):

def video_upload(video, offer_pk):

chunk_size = (130 * 1024 * 1024)  # 200 MB

#Initial sending, get an upload link
url = 'https://api.vimeo.com/me/videos'
headers = {
'Authorization': 'bearer %s' % settings.VIMEO_TOKEN, 'Content-Type' : 'application/json', 'Accept' : 'application/vnd.vimeo.*+json;version=3.4'}

data = {'upload' :{ 'approach' : 'tus', 'size' : video.size}, 'name' : str(offer_pk)}

r = requests.post(url, headers=headers, data=json.dumps(data))

if r.status_code == 200:

    uri = r.json()['uri'] # link to final video
    upload_link = r.json()['upload']['upload_link']
    approach = r.json()['upload']['approach']#should be tus

    if approach == 'tus':

        try:
            tus_client = client.TusClient('https://files.tus.vimeo.com')
            uploader = tus_client.uploader(
                    chunk_size=chunk_size,
                    file_stream=video,
                    retries=3,
                    url=upload_link)
            uploader.upload()
        except Exception as e:
            raise exceptions.VideoUploadFailure(
                e,
                'Unexpected error when uploading through tus.'
            )

        result = uploader.verify_upload()
        if result == True:
            return uri 
jaylinski commented 4 years ago

Version 1.1.0 uses an update tuspy version. Maybe this helps.

fisherinnovation commented 4 years ago

@typefox09 Are you still experiencing this in the latest version?

typefox09 commented 4 years ago

Hi, I changed my implementation to having the video uploaded on the client side with the tus js package. Now it's only effected by the clients internet speed. Thank you for following up on this. Is there anyway to improve the speed further from what I am currently doing?

On Wed, 29 Jul. 2020, 01:33 Matt Fisher, notifications@github.com wrote:

@typefox09 https://github.com/typefox09 Are you still experiencing this in the latest version?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/vimeo/vimeo.py/issues/157#issuecomment-665110894, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOXSUY3XJ7DBEXYGEFPLTETR53VTZANCNFSM4NFTBHBQ .