0

I am new to interfacing with the Dropbox API and am using Python 3.6

I am uploading large files to my account using the following function called dropboxupload (not my own) . I simply call it at the end of my code:

import os
import sys
from tqdm import tqdm
import dropbox

filenameonly = sys.argv[1]
filenamewithextension = sys.argv[2]
fullfilepath = sys.argv[3]

access_token = "removedforsecurity"

def dropboxupload(access_token,file_path,target_path,timeout=3600,chunk_size=150 * 1024 * 1024,):
    dbx = dropbox.Dropbox(access_token, timeout=timeout)
    with open(file_path, "rb") as f:
        file_size = os.path.getsize(file_path)
        chunk_size = 150 * 1024 * 1024
        if file_size <= chunk_size:
            print(dbx.files_upload(f.read(), target_path))
        else:
            with tqdm(total=file_size, desc="Uploaded") as pbar:
                upload_session_start_result = dbx.files_upload_session_start(
                    f.read(chunk_size)
                )
                pbar.update(chunk_size)
                cursor = dropbox.files.UploadSessionCursor(
                    session_id=upload_session_start_result.session_id,
                    offset=f.tell(),
                )
                commit = dropbox.files.CommitInfo(path=target_path)
                while f.tell() < file_size:
                    if (file_size - f.tell()) <= chunk_size:
                        print(
                            dbx.files_upload_session_finish(
                                f.read(chunk_size), cursor, commit
                            )
                        )
                    else:
                        dbx.files_upload_session_append(
                            f.read(chunk_size),
                            cursor.session_id,
                            cursor.offset,
                        )
                        cursor.offset = f.tell()
                    pbar.update(chunk_size)

dropboxupload(access_token, fullfilepath, "/"+filenamewithextension)

It works perfectly.

The response that comes back automatically is the FileMetadata; example as follows:

FileMetadata(name='500.mp4', id='id:a5yk0DAylOAAAAAAAAADbA', client_modified=datetime.datetime(2020, 2, 19, 13, 56, 31), server_modified=datetime.datetime(2020, 2, 19, 13, 56, 31), rev='59eee27d89b134c0970a9', size=512727070, path_lower='/500.mp4', path_display='/500.mp4', parent_shared_folder_id=None, media_info=None, symlink_info=None, sharing_info=None, is_downloadable=True, export_info=None, property_groups=None, has_explicit_shared_members=None, content_hash='e134be9c61057696145fbe4c416d5e62c983649bb756c9e9597d982781a1cb83')

What i want to do is capture this response and use the data within it for other means in the next step of my project.

For example i want to take the id and set as a new variable called "data". I have tried doing this with

data = str(dropbox.files.FileMetadata.id)
print ("THE DATA VARIABLE IS")
print(data)

but all that gets printed is....

THE DATA VARIABLE IS
property object at 0x03A82F60

I am obviously capturing the data wrong - please can you help?!

Thanks

1

1 Answer 1

0

I think what you want to do is this:

data = dropbox.files.FileMetadata.id()
2
  • Thanks again, I did try that before the OP, and it still shows the same THE DATA VARIABLE IS property object at 0x03A82F60
    – yekootmada
    Commented Feb 19, 2020 at 16:12
  • For what it's worth I edited my answer. I think that should solve your problem :)
    – Martin S
    Commented Feb 21, 2020 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.