Python script for uploading files to box using OAuth2

New post



  • Howard

    Hi ,


    Thanks for your post. Have you checked out our developer documentation here?

    That may help you get started with uploads and other Box actions. Thanks for clarifying and checking out the link!

    Comment actions Permalink
  • bhanuprakashemm


    Helo Howard,


    Is there any script which does the same, not from searching thru box content.

    I need an end to end which accepts folder, and uploads them to box -- I can manage the token refresh for uninterrupted uploads ?



    Comment actions Permalink
  • Jason

     Unfortunately Box's API does not accept a folder as an input. You must create a folder and specify individual files for upload in separate requests. 


    You can see some excerpts here for uploading an individual file:


    And creating a folder:


    If you are doing this through a front-end, you may wish to use our Content Uploader Javascript library:


    Hope that helps! Let us know if you have any other questions!




    Comment actions Permalink
  • VBK

    Is there a way to make the upload function force overwrite of existing files? I'm currently getting the following error:

    BoxAPIException: Message: Item with the same name already exists
    Status: 409
    Code: item_name_in_use

    Ideally, I would like for the file to be overwritten, and version number of the file incremented.  

    Comment actions Permalink
  • VBK

    I figured it out:


        new_file = client.folder(folder_id).upload(local_file_path)
    except BoxAPIException as e:
        print('File %s exists. Updating contents.'%local_file_path)
        file_id = e.context_info['conflicts']['id']
        new_file = client.file(file_id).update_contents(local_file_path)


    Comment actions Permalink

Please sign in to leave a comment.