upload file to my dropbox from python script

dropbox python api v2 upload file
dropbox api
upload file using python script
dropbox python style guide
dropbox create app
dropbox component
how to code dropbox
dropbox components

I want to upload a file from my python script to my dropbox account automatically. I can't find anyway to do this with just a user/pass. Everything I see in the Dropbox SDK is related to an app having user interaction. I just want to do something like this:

https://api-content.dropbox.com/1/files_put//?user=me&pass=blah

The answer of @Christina is based on Dropbox APP v1, which is deprecated now and will be turned off on 6/28/2017. (Refer to here for more information.)

APP v2 is launched in November, 2015 which is simpler, more consistent, and more comprehensive.

Here is the source code with APP v2.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import dropbox

class TransferData:
    def __init__(self, access_token):
        self.access_token = access_token

    def upload_file(self, file_from, file_to):
        """upload a file to Dropbox using API v2
        """
        dbx = dropbox.Dropbox(self.access_token)

        with open(file_from, 'rb') as f:
            dbx.files_upload(f.read(), file_to)

def main():
    access_token = '******'
    transferData = TransferData(access_token)

    file_from = 'test.txt'
    file_to = '/test_dropbox/test.txt'  # The full path to upload the file to, including the file name

    # API v2
    transferData.upload_file(file_from, file_to)

if __name__ == '__main__':
    main()

The source code is hosted on GitHub, here.

Simple python script to upload file to Dropbox. · GitHub, Once done with code, run the script by following command. # $ python SFileUploader.py // if python3.5 is default. import sys. import dropbox. from dropbox.files  13 Go to the Dropbox > Files > Upload page in our code generation library. From the drop down menu at the top of the page, select Python. 14 In the INPUT section of the page, enter your Dropbox AccessToken.

Important Note: this answer is deprecated since dropbox uses v2 API now. See the answer of @SparkAndShine for current API version solution

Thanks to @smarx for the answer above! I just wanted to clarify for anyone else trying to do this.

  1. Make sure you install the dropbox module first of course, pip install dropbox.

  2. Create an app under your own dropbox account in the "App Console". (https://www.dropbox.com/developers/apps)

  3. Just for the record I created my App with the following:

    a. App Type as "Dropbox API APP".

    b. Type of data access as "Files & Datastores"

    c. Folder access as "My app needs access to files already on Dropbox". (ie: Permission Type as "Full Dropbox".)

  4. Then click the "generate access token" button and cut/paste into the python example below in place of <auth_token>:

import dropbox client = dropbox.client.DropboxClient(<auth_token>) print 'linked account: ', client.account_info() f = open('working-draft.txt', 'rb') response = client.put_file('/magnum-opus.txt', f) print 'uploaded: ', response folder_metadata = client.metadata('/') print 'metadata: ', folder_metadata f, metadata = client.get_file_and_metadata('/magnum-opus.txt') out = open('magnum-opus.txt', 'wb') out.write(f.read()) out.close() print metadata

Downloading or uploading files into dropbox using, python script to download and upload a file to the dropbox. Make sure that your app has a data access type of “Files & Datastores,” and set your permission type to “Full Dropbox.” This will ensure that your app has write access, so you won’t run into any errors when uploading files from your script. Finally, click “generate access token” and copy down the string that is produced. We’ll need that for your script to properly work, and we’ll plug it in below where the script calls for it.

Here's my approach using API v2 (and Python 3). I wanted to upload a file and create a share link for it, which I could email to users. It's based on sparkandshine's example. Note I think the current API documentation has a small error which sparkandshine has corrected.

import pathlib
import dropbox
import re

# the source file
folder = pathlib.Path(".")    # located in this folder
filename = "test.txt"         # file name
filepath = folder / filename  # path object, defining the file

# target location in Dropbox
target = "/Temp/"              # the target folder
targetfile = target + filename   # the target path and file name

# Create a dropbox object using an API v2 key
d = dropbox.Dropbox(your_api_access_token)

# open the file and upload it
with filepath.open("rb") as f:
   # upload gives you metadata about the file
   # we want to overwite any previous version of the file
   meta = d.files_upload(f.read(), targetfile, mode=dropbox.files.WriteMode("overwrite"))

# create a shared link
link = d.sharing_create_shared_link(targetfile)

# url which can be shared
url = link.url

# link which directly downloads by replacing ?dl=0 with ?dl=1
dl_url = re.sub(r"\?dl\=0", "?dl=1", url)
print (dl_url)

Monday Mentorship: Using Python to Upload a File to Dropbox , We'll need that for your script to properly work, and we'll plug it in below where the script calls for it. Great, that's all we need to do on Dropbox's  I want to upload a file from my python script to my dropbox account automatically. I can't find anyway to do this with just a user/pass. Everything I see in the Dropbox SDK is related to an app h

The only way to authenticate calls to the Dropbox API is to use OAuth, which involves the user giving permission to your app. We don't allow third-party apps to handle user credentials (username and password).

If this is just for your account, note that you can easily get an OAuth token for your own account and just use that. See https://www.dropbox.com/developers/blog/94/generate-an-access-token-for-your-own-account.

If this is for other users, they'll need to authorize your app once via the browser for you to get an OAuth token. Once you have the token, you can keep using it, though, so each user should only have to do this once.

Python SDK, Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily. Never email yourself a file again! For large files like this, you'll need to use upload sessions. Otherwise, you'll run in to issues like the error you posted. This uses the Dropbox Python SDK to upload a file to the Dropbox API from the local file as specified by file_path to the remote path as specified by dest_path.

import dropbox
access_token = '************************'
file_from = 'index.jpeg'  //local file path
file_to = '/Siva/index.jpeg'      // dropbox path
def upload_file(file_from, file_to):
    dbx = dropbox.Dropbox(access_token)
    f = open(file_from, 'rb')
    dbx.files_upload(f.read(), file_to)
upload_file(file_from,file_to)

Python - Developers, Here's how to use Temboo's Python SDK to upload a file to Dropbox in your Python application. 3Download the Temboo Python SDK and extract the .zip file to the same directory as 22Now you're ready to run the script and see the output. sorry, I imagined somewhere you were calling Dropbox put_file method. Here is wepapp put_file and you seems to never ask dropbox such a thing. I advice you to get an incremental approach to your program, starting with a small working local application and solve your challenges (webapp, auth) once at time.

How to Upload a File to Dropbox in Python, This post is all about uploading files to Dropbox using Dropbox-API in Python. Dropbox API is used in OpenCV programs to upload the frames to the cloud. Dropbox for Python. Here's our Python SDK for API v2, which helps you easily integrate Dropbox into your Python app. Code. Dropbox for Python - Dropbox for Python SDK is open source on GitHub. Sample apps. back-up-and-restore.py - Simple app that shows how to back up user files and restore them to a specific revision.

Python Upload Files to Dropbox, Yesterday, I stumbled on to Dropbox's Python API. that can access your dropbox folder, as well as download and upload files to dropbox but I always got an error about my token being expired, so this script will always pop  Depending on your Linux distribution and the package you used to perform installation, you may need to download a Python script to control Dropbox from the command line. However, we recommend you first try without downloading the script.

Uploading files using Dropbox-API in Python, If you choose Files, select as many files as you like and click Open. If you choose Folder, select a folder and click Upload. Note: Each file or folder that you upload through dropbox.com must be 50 GB or smaller. For larger files or folders, use the desktop or mobile apps, which don’t have a file size limit.

Comments
  • Can I get a comment with the downvote please? So I can improve the question?
  • There are examples included in the official SDK: github.com/dropbox/dropbox-sdk-python/tree/master/example
  • The only way I could get that to work was to change it to: dbx.files_upload(f.read(), file_to)
  • @SteveLockwood, It tested it 1 year ago and it worked. Anyway, I updated my answer as you suggested.
  • I wonder if that's a python 2/3 difference - my example is tested with python 3
  • @SteveLockwood, I tested it with python2.
  • As highlighted by SparkAndShine below, this is for Dropbox API v1 and is now deprecated.
  • how can I upload file from S3 URL to dropbox?
  • It should be noted that the newer Dropbox libraries that support v2 require so many different libraries that they eat up all the memory on the device and crash, if you are on a minimal linux environment like the Arduino Yun. :(
  • it is that easy.
  • Ha ha. Yes you are. The 0riginal poster is trying to do this programatically.
  • Well, to be precise, this IS a valid solution IMHO. You can save the file in the corresponding directory "programatically" (I like the neologism), and then the Dropbox application will sync it with your account without further user interaction.