I am trying to use the upload_chunked() method in the ChunkedUploader class in the Dropbox API. I wrote the following code to accomplish it.
Constructor of my class DropboxApp
import webbrowser
from configobj import ConfigObj
from dropbox import *
class DropboxApp:
def __init__(self): #constructor
app_key = 'xxxxxxxxxx'
app_secret = 'xxxxxxxxxx'
access_type = "dropbox"
TOKENS = './dropbox_token.txt'
#first check if the user has already authenticated the app before
try:
token_file = open(TOKENS)
token_key,token_secret = token_file.read().split('|')
token_file.close()
sess = dropbox.session.DropboxSession(app_key,app_secret,access_type )
sess.set_token(token_key,token_secret)
self.client = dropbox.client.DropboxClient(sess)
self.client2 = dropbox.client.ChunkedUploader(sess)
#if the user is using the app for the first time, we'll have to authenticate the app first
except:
session = dropbox.session.DropboxSession(app_key,app_secret,access_type)
request_token = session.obtain_request_token()
url = session.build_authorize_url(request_token)
webbrowser.open_new_tab(url)
raw_input("Press enter to continue")
access_token = session.obtain_access_token(request_token)
self.client = dropbox.client.DropboxClient(session)
self.client2 = dropbox.client.ChunkedUploader(session)
#save the tokens so that the user doesn't have to authenticate again
token_file = open(TOKENS,'w')
token_file.write("%s|%s" % (access_token.key,access_token.secret) )
token_file.close()
and this is the method to upload content
def upload_cont(self, upload):
#upload --> the exact path of where the file to be uploaded is stored on the user's directory
f = open(upload)
self.client2.upload_chunked()
response = self.client2.finish('/uploaded.txt', f)
print "uploaded:", response
But when I run this method I get the following error
Traceback (most recent call last):
File "/home/archit/Documents/Dropbox/dropbox-api-dev/first_app_1.0.py", line 75, in <module>
drop = DropboxApp()
File "/home/archit/Documents/Dropbox/dropbox-api-dev/first_app_1.0.py", line 35, in __init__
self.client2 = dropbox.client.ChunkedUploader(session)
AttributeError: 'module' object has no attribute 'ChunkedUploader'
I am not sure what that means. Please tell me where am I going wrong?