Forum Discussion

JASMINA V.'s avatar
JASMINA V.
New member | Level 1
10 years ago

how can i upload saved or webcam images and videos on dropbox from python?

i have installed python version 2.7.also i have installed required libraries like opencv and numpy.

Using this library i have done image and video processing which are captured from webcam and also from existing file..these all things work fine with me.

I have know how to access dropbox using python through that ACCESS TOKEN.

Now i have to upload all these things- (means captured videos and images) to my dropbox account from python program.

I have seached a lot for that...but i didn't get code for uploading images and videos on dropbox with the help of python.

So, can anybody suggest me what is the code for the above problem. 

3 Replies

Replies have been turned off for this discussion
  • JASMINA V.'s avatar
    JASMINA V.
    New member | Level 1
    10 years ago

    Hey,

    Here is the the code for uploading live videos on your dropbox account using python in windows.

     

    import numpy as np
    import cv2
    import dropbox
    import os
    from glob import iglob


    access_token = 'paste your access token here'   #paste your access token in-between ''
    client = dropbox.client.DropboxClient(access_token)
    print 'linked account: ', client.account_info()
    PATH = ''

    cap = cv2.VideoCapture(0)


    # Define the codec and create VideoWriter object
    fourcc = cv2.VideoWriter_fourcc(*'XVID')
    out = cv2.VideoWriter('C:\python27\output1.avi',fourcc, 20.0, (640,480))

    #here output1.avi is the filename in which your video which is captured from webcam is stored. and it resides in C:\python27 as per the path is given.

    while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
    #frame = cv2.flip(frame,0) #if u want to flip your video

    # write the (unflipped or flipped) frame
    out.write(frame)

    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
    break
    else:
    break

    # Release everything if job is finished
    cap.release()
    out.release()
    cv2.destroyAllWindows()

    for filename in iglob(os.path.join(PATH, 'C:/Python27/output1.avi')):
    print filename
    try:
    f = open(filename, 'rb')
    response = client.put_file('/livevideo1.avi', f)
    print "uploaded:", response
    f.close()
    #os.remove(filename)
    except Exception, e:
    print 'Error %s' % e

     

     

    Hope this will  help you.

  • JASMINA V.'s avatar
    JASMINA V.
    New member | Level 1
    10 years ago

    Hey,

    Here is the code for uploading existing video on your dropbox account using python in windows.

    Hope this will help you.

     

    # Include the Dropbox SDK
    import dropbox

    # Get your app key and secret from the Dropbox developer website
    app_key = 'paste your app-key here'
    app_secret = 'paste your app-secret here'

    flow = dropbox.client.DropboxOAuth2FlowNoRedirect(app_key, app_secret)

    # Have the user sign in and authorize this token
    authorize_url = flow.start()
    print '1. Go to: ' + authorize_url
    print '2. Click "Allow" (you might have to log in first)'
    print '3. Copy the authorization code.'
    code = raw_input("Enter the authorization code here: ").strip()

    # This will fail if the user enters an invalid authorization code
    access_token, user_id = flow.finish(code)

    client = dropbox.client.DropboxClient(access_token)
    print 'linked account: ', client.account_info()

    f = open('give full path of the video which u want to upload on your dropbox account(ex: C:\python27\examples\video.avi)', 'rb')
    response = client.put_file('/video1.avi', f) #video1.avi is the name in which your video is shown on your dropbox account. You can give any name here.
    print 'uploaded: ', response

    folder_metadata = client.metadata('/')
    print 'metadata: ', folder_metadata

    f, metadata = client.get_file_and_metadata('/video1.avi')
    out = open('video1.avi', 'wb')
    out.write(f.read())
    out.close()
    print metadata

     

     

     

    Now for uploading images, the same code will be used.

    Only write your image file name which you want to upload for ex: image.jpg in place of video name . Also change the name of video1.avi and write name for image in which your uploaded image will be shown in your dropbox for ex:image1.jpg.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!