cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Check out the Dropbox cheat sheet for getting started in 2021 here!

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Incorrect type expected on upload [ Python ]

Incorrect type expected on upload [ Python ]

New member | Level 2

So Im trying to upload some multiple files using API, but in the end I just getting

dropbox.stone_validators.ValidationError: '<_io.BufferedReader name='./image_01.jpg'>' expected to be a string, got BufferedReader

My code: 

def image_uploader(filename):

    filename_lower = filename.lower()

    for ignored_file in IGNORED_FILES:
        if ignored_file in filename_lower:
            return True

    return False


local_dir = '.'
dbx_token = dropbox.Dropbox('MY_API_TOKEN')


for root, dirs, files in os.walk(local_dir):

    for file_name in files:
        if image_uploader(file_name):
            continue

        local_path = os.path.join(root, file_name)
        relative_path = os.path.relpath(local_path, local_dir)
        dropbox_path = os.path.join('/Apps/face_db_upload', relative_path)

        with open(local_path, 'rb') as f:
            dbx_token.files_upload(dropbox_path, f)

 

1 Reply 1

Re: Incorrect type expected on upload [ Python ]

Dropboxer

The files_upload method expects a string, but you're passing in a file object. You'll need to update your code to pass in a string, e.g., try passing in `f.read()` instead of `f`.

Polls
Are you starting new work habits this year?

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?