Title: | Programmatic Interface to the 'Dropbox' API |
---|---|
Description: | Provides full programmatic access to the 'Dropbox' file hosting platform <https://dropbox.com>, including support for all standard file operations. |
Authors: | Karthik Ram [aut, cre], Clayton Yochum [aut], Caleb Scheidel [ctb], Akhil Bhel [cph] |
Maintainer: | Karthik Ram <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.8.2.2 |
Built: | 2024-11-13 04:43:54 UTC |
Source: | https://github.com/fcampelo/rdrop2 |
Fields returned will vary by account;
drop_acc(dtoken = get_dropbox_token())
drop_acc(dtoken = get_dropbox_token())
dtoken |
The Dropbox token generated by |
Nested list with elements account_id
,
name
(list), email
, email_verified
, disabled
,
locale
, referral_link
, is_paired
, account_type
(list).
If available, may also return profile_photo_url
,
country
, team
(list), team_member_id
.
## Not run: acc_info <- drop_acc() # extract display name acc_info$name$display_name ## End(Not run)
## Not run: acc_info <- drop_acc() # extract display name acc_info$name$display_name ## End(Not run)
This function authenticates you into Dropbox. The documentation for the core Dropbox API provides more details including alternate methods if you desire to reimplement your own.
drop_auth( new_user = FALSE, key = "mmhfsybffdom42w", secret = "l8zeqqqgm1ne5z0", cache = TRUE, rdstoken = NA )
drop_auth( new_user = FALSE, key = "mmhfsybffdom42w", secret = "l8zeqqqgm1ne5z0", cache = TRUE, rdstoken = NA )
new_user |
Set to |
key |
Your application key. |
secret |
Your application secret. Like |
cache |
By default your credentials are locally cached in a file called
|
rdstoken |
File path to stored RDS token. In server environments where interactive OAuth is not possible, a token can be created on a desktop client and used in production. See examples. |
A Token2.0 object, invisibly
## Not run: # To either read token from .httr-oauth in the working directory or open a # web browser to authenticate (and cache a token) drop_auth() # If you want to overwrite an existing local token and switch to a new # user, set new_user to TRUE. drop_auth(new_user = TRUE) # To store a token for re-use (more flexible than .httr-oauth), save the # output of drop_auth and save it to an RDS file token <- drop_auth() saveRDS(token, "/path/to/tokenfile.RDS") # To use a stored token provide token location drop_auth(rdstoken = "/path/to/tokenfile.RDS") ## End(Not run)
## Not run: # To either read token from .httr-oauth in the working directory or open a # web browser to authenticate (and cache a token) drop_auth() # If you want to overwrite an existing local token and switch to a new # user, set new_user to TRUE. drop_auth(new_user = TRUE) # To store a token for re-use (more flexible than .httr-oauth), save the # output of drop_auth and save it to an RDS file token <- drop_auth() saveRDS(token, "/path/to/tokenfile.RDS") # To use a stored token provide token location drop_auth(rdstoken = "/path/to/tokenfile.RDS") ## End(Not run)
Compute a "content hash" using the same algorithm as dropbox. This
can be used to verify the content against the content_hash
field returned in drop_dir
.
drop_content_hash(file)
drop_content_hash(file)
file |
A vector of filenames |
Dropbox returns a hash of file contents in drop_dir
.
However, this is not a straightforward file hash. Instead the file
is divided into 4MB chunks, each of those is hashed and then the
concatenation of the hashes is itself hashed (see
this
page in the dropbox developer documentation for the details).
It's entirely unclear why it does not compute a hash of the file
itself, but here we are.
A character vector the same length as file
. Each
element is 64 character string which is the unique hash. Two
files that have the same hash have the same contents. Compare
this hash of a local file with the content_hash
field from
drop_dir
to see if you have the same file as
dropbox.
## Not run: write.csv(mtcars, file = "mtt.csv") drop_upload("mtt.csv") files <- drop_dir() # Dropbox's reported hash files$content_hash[files$name == "mtt.csv"] # Our computed hash: drop_content_hash("mtt.csv") ## End(Not run)
## Not run: write.csv(mtcars, file = "mtt.csv") drop_upload("mtt.csv") files <- drop_dir() # Dropbox's reported hash files$content_hash[files$name == "mtt.csv"] # Our computed hash: drop_content_hash("mtt.csv") ## End(Not run)
Copies a file or folder to a new location.
drop_copy( from_path = NULL, to_path = NULL, allow_shared_folder = FALSE, autorename = FALSE, allow_ownership_transfer = FALSE, verbose = FALSE, dtoken = get_dropbox_token() )
drop_copy( from_path = NULL, to_path = NULL, allow_shared_folder = FALSE, autorename = FALSE, allow_ownership_transfer = FALSE, verbose = FALSE, dtoken = get_dropbox_token() )
from_path |
Source file or folder |
to_path |
destination file or folder |
allow_shared_folder |
If |
autorename |
If there's a conflict, have the Dropbox server try to autorename the file to avoid the conflict. |
allow_ownership_transfer |
Allow moves by owner even if it would result in an ownership transfer for the content being moved. This does not apply to copies. The default for this field is False. |
verbose |
By default verbose output is |
dtoken |
The Dropbox token generated by |
## Not run: write.csv(mtcars, file = "mt.csv") drop_upload("mt.csv") drop_create("drop_test2") drop_copy("mt.csv", "drop_test2/mt2.csv") ## End(Not run)
## Not run: write.csv(mtcars, file = "mt.csv") drop_upload("mt.csv") drop_create("drop_test2") drop_copy("mt.csv", "drop_test2/mt2.csv") ## End(Not run)
Returns a list containing the following fields: "size", "rev", "thumb_exists", "bytes", "modified", "path", "is_dir", "icon", "root", "revision"
drop_create( path = NULL, autorename = FALSE, verbose = FALSE, dtoken = get_dropbox_token() )
drop_create( path = NULL, autorename = FALSE, verbose = FALSE, dtoken = get_dropbox_token() )
path |
Path in the user's Dropbox, relative to root |
autorename |
Set to |
verbose |
By default verbose output is |
dtoken |
The Dropbox token generated by |
## Not run: drop_create(path = "foobar") ## End(Not run)
## Not run: drop_create(path = "foobar") ## End(Not run)
Deletes a file or folder.
drop_delete(path = NULL, verbose = FALSE, dtoken = get_dropbox_token())
drop_delete(path = NULL, verbose = FALSE, dtoken = get_dropbox_token())
path |
Path in the user's Dropbox, relative to root |
verbose |
By default verbose output is |
dtoken |
The Dropbox token generated by |
Can be used to either see all items in a folder, or only items that have changed since a previous request was made.
drop_dir( path = "", recursive = FALSE, include_media_info = FALSE, include_deleted = FALSE, include_has_explicit_shared_members = FALSE, include_mounted_folders = TRUE, limit = NULL, cursor = FALSE, dtoken = get_dropbox_token() )
drop_dir( path = "", recursive = FALSE, include_media_info = FALSE, include_deleted = FALSE, include_has_explicit_shared_members = FALSE, include_mounted_folders = TRUE, limit = NULL, cursor = FALSE, dtoken = get_dropbox_token() )
path |
path to folder in Dropbox to list contents of. Defaults to the root directory. |
recursive |
If TRUE, the list folder operation will be applied recursively to all subfolders and the response will contain contents of all subfolders. Defaults to FALSE. |
include_media_info |
If TRUE, FileMetadata.media_info is set for photo and video. Defaults to FALSE. |
include_deleted |
If TRUE, the results will include entries for files and folders that used to exist but were deleted. Defaults to FALSE. |
include_has_explicit_shared_members |
If TRUE, the results will include a flag for each file indicating whether or not that file has any explicit members. Defaults to FALSE. |
include_mounted_folders |
If TRUE, the results will include entries under mounted folders which includes app folder, shared folder and team folder. Defaults to TRUE. |
limit |
The maximum number of results to return per request. Note: This is an approximate number and there can be slightly more entries returned in some cases. Defaults to NULL, no limit. |
cursor |
string or boolean:
|
dtoken |
The Dropbox token generated by |
Either a tbl_df
of items in folder, one row per file or folder, with metadata values as columns, or a character string giving a cursor to be used later for change detection (see cursor
).
## Not run: # list files in root directory drop_dir() # get a cursor from root directory, # upload a new file, # return only information about new file cursor <- drop_dir(cursor = TRUE) drop_upload("some_new_file") drop_dir(cursor = cursor) ## End(Not run)
## Not run: # list files in root directory drop_dir() # get a cursor from root directory, # upload a new file, # return only information about new file cursor <- drop_dir(cursor = TRUE) drop_upload("some_new_file") drop_dir(cursor = cursor) ## End(Not run)
Download a file from Dropbox to disk.
drop_download( path, local_path = NULL, overwrite = FALSE, progress = interactive(), verbose = interactive(), dtoken = get_dropbox_token() )
drop_download( path, local_path = NULL, overwrite = FALSE, progress = interactive(), verbose = interactive(), dtoken = get_dropbox_token() )
path |
path to a file in Dropbox |
local_path |
path to save file to. If NULL (the default), saves file to working directory with same name. If not null, but a valid folder, file will be saved in this folder with same basename as path. If not null and not a folder, file will be saved to this path exactly. |
overwrite |
If TRUE, overwrite local file. Defaults to FALSE |
progress |
If TRUE, show a progress bar for large file downloads. Defaults to TRUE in interactive sessions, otherwise FALSE. |
verbose |
if TRUE, emit message giving location and size of the newly downloaded file. Defaults to TRUE in interactive sessions, otherwise FALSE. |
dtoken |
The Dropbox token generated by |
TRUE if successful; error thrown otherwise.
## Not run: # download a file to the current working directory drop_get("dataset.zip") # download again, overwriting previous result drop_get("dataset.zip", overwrite = TRUE) # download to a different path, keeping file name constant # will download to "some/other/place/dataset.zip" drop_get("dataset.zip", local_path = "some/other/place/") # download to to a different path, changing filename drop_get("dataset.zip", local_path = "some/other/place/not_a_dataset.zip") ## End(Not run)
## Not run: # download a file to the current working directory drop_get("dataset.zip") # download again, overwriting previous result drop_get("dataset.zip", overwrite = TRUE) # download to a different path, keeping file name constant # will download to "some/other/place/dataset.zip" drop_get("dataset.zip", local_path = "some/other/place/") # download to to a different path, changing filename drop_get("dataset.zip", local_path = "some/other/place/not_a_dataset.zip") ## End(Not run)
Since many file operations such as move, copy, delete and history can only act
on files that currently exist on a Dropbox store, checking to see if the
path
is valid before operating prevents bad API calls from being sent
to the server. This functions returns a logical response after checking if a
file path is valid on Dropbox.
drop_exists(path = NULL, dtoken = get_dropbox_token())
drop_exists(path = NULL, dtoken = get_dropbox_token())
path |
The full path to a Dropbox file |
dtoken |
The Dropbox token generated by |
boolean; TRUE is the file or folder exists, FALSE if it does not.
## Not run: drop_create("existential_test") drop_exists("existential_test") drop_delete("existential_test") ## End(Not run)
## Not run: drop_create("existential_test") drop_exists("existential_test") drop_delete("existential_test") ## End(Not run)
Downloads a file from Dropbox
drop_get( path = NULL, local_file = NULL, overwrite = FALSE, verbose = FALSE, progress = FALSE, dtoken = get_dropbox_token() )
drop_get( path = NULL, local_file = NULL, overwrite = FALSE, verbose = FALSE, progress = FALSE, dtoken = get_dropbox_token() )
path |
Path in the user's Dropbox, relative to root |
local_file |
The name of the local copy. Leave this blank if you're fine with the original name. |
overwrite |
Default is |
verbose |
By default verbose output is |
progress |
Progress bars are turned off by default. Set to |
dtoken |
The Dropbox token generated by |
## Not run: drop_get(path = 'dataset.zip', local_file = "~/Desktop") # To overwrite the existing file drop_get(path = 'dataset.zip', overwrite = TRUE) ## End(Not run)
## Not run: drop_get(path = 'dataset.zip', local_file = "~/Desktop") # To overwrite the existing file drop_get(path = 'dataset.zip', overwrite = TRUE) ## End(Not run)
Details vary by input and args.
drop_get_metadata( path, include_media_info = FALSE, include_deleted = FALSE, include_has_explicit_shared_members = FALSE, dtoken = get_dropbox_token() )
drop_get_metadata( path, include_media_info = FALSE, include_deleted = FALSE, include_has_explicit_shared_members = FALSE, dtoken = get_dropbox_token() )
path |
Path to a file or folder on Dropbox. Can also be an ID ("id:...") or revision ("rev:..."). |
include_media_info |
If TRUE, additional metadata for photo or video is returns. Defaults to FALSE. |
include_deleted |
If TRUE, metadata will be returned for a deleted file, otherwise error. Defaults to FALSE. |
include_has_explicit_shared_members |
If TRUE, the results will include a flag for each file indicating whether or not that file has any explicit members. Defaults to FALSE. |
dtoken |
The Dropbox token generated by |
possibly-nested list of all available metadata for specified file/folder/id/revision.
Does not include deleted revisions.
drop_history(path, limit = 10, dtoken = get_dropbox_token())
drop_history(path, limit = 10, dtoken = get_dropbox_token())
path |
path to a file in dropbox. |
limit |
maximum number of revisions to return; defaults to 10. |
dtoken |
The Dropbox token generated by |
tbl_df
of metadata, one row per revision.
## Not run: write.csv(iris, file = "iris.csv") drop_upload("iris.csv") write.csv(iris[iris$Species == "setosa", ], file = "iris.csv") drop_upload("iris.csv") drop_history("iris.csv") ## End(Not run)
## Not run: write.csv(iris, file = "iris.csv") drop_upload("iris.csv") write.csv(iris[iris$Species == "setosa", ], file = "iris.csv") drop_upload("iris.csv") drop_history("iris.csv") ## End(Not run)
Similar to drop_shared
. The difference is that this bypasses the
Dropbox webserver, used to provide a preview of the file, so that you can
effectively stream the contents of your media. This URL should not be used to
display content directly in the browser. IMPORTANT: The media link will expire
after 4 hours. So you'll need to cache the content with knitr cache OR re-run
the function call after expiry.
drop_media(path = NULL, dtoken = get_dropbox_token())
drop_media(path = NULL, dtoken = get_dropbox_token())
path |
Path in the user's Dropbox, relative to root |
dtoken |
The Dropbox token generated by |
## Not run: drop_media('Public/gifs/duck_rabbit.gif') ## End(Not run)
## Not run: drop_media('Public/gifs/duck_rabbit.gif') ## End(Not run)
Moves a file or folder to a new location.
drop_move( from_path = NULL, to_path = NULL, allow_shared_folder = FALSE, autorename = FALSE, allow_ownership_transfer = FALSE, verbose = FALSE, dtoken = get_dropbox_token() )
drop_move( from_path = NULL, to_path = NULL, allow_shared_folder = FALSE, autorename = FALSE, allow_ownership_transfer = FALSE, verbose = FALSE, dtoken = get_dropbox_token() )
from_path |
Source file or folder |
to_path |
destination file or folder |
allow_shared_folder |
If |
autorename |
If there's a conflict, have the Dropbox server try to autorename the file to avoid the conflict. |
allow_ownership_transfer |
Allow moves by owner even if it would result in an ownership transfer for the content being moved. This does not apply to copies. The default for this field is False. |
verbose |
By default verbose output is |
dtoken |
The Dropbox token generated by |
## Not run: write.csv(mtcars, file = "mt.csv") drop_upload("mt.csv") drop_create("drop_test2") drop_move("mt.csv", "drop_test2/mt.csv") ## End(Not run)
## Not run: write.csv(mtcars, file = "mt.csv") drop_upload("mt.csv") drop_create("drop_test2") drop_move("mt.csv", "drop_test2/mt.csv") ## End(Not run)
A lightweight wrapper around read.csv
to read csv files from Dropbox into memory
drop_read_csv(file, dest = tempdir(), dtoken = get_dropbox_token(), ...)
drop_read_csv(file, dest = tempdir(), dtoken = get_dropbox_token(), ...)
file |
Name of file with full path relative to Dropbox root |
dest |
A temporary directory where a csv file is downloaded before being read into memory |
dtoken |
The Dropbox token generated by |
... |
Additional arguments into |
## Not run: write.csv(iris, file = "iris.csv") drop_upload("iris.csv") # Now let's read this back into an R session new_iris <- drop_read_csv("iris.csv") ## End(Not run)
## Not run: write.csv(iris, file = "iris.csv") drop_upload("iris.csv") # Now let's read this back into an R session new_iris <- drop_read_csv("iris.csv") ## End(Not run)
Returns metadata for all files and folders whose filename contains the given search string as a substring.
drop_search( query, path = "", start = 0, max_results = 100, mode = "filename", dtoken = get_dropbox_token() )
drop_search( query, path = "", start = 0, max_results = 100, mode = "filename", dtoken = get_dropbox_token() )
query |
The search string. This string is split (on spaces) into individual words. Files and folders will be returned if they contain all words in the search string. |
path |
Path in the user's Dropbox, relative to root |
start |
The starting index within the search results (used for paging). The default for this field is 0 |
max_results |
The maximum number of search results to return. The default for this field is 100. |
mode |
Mode can take the option of filename, filename_and_content, or search deleted files with deleted_filename |
dtoken |
The Dropbox token generated by |
## Not run: # If you know me, you know why this query exists drop_search('gif') %>% select(path, is_dir, mime_type) ## End(Not run)
## Not run: # If you know me, you know why this query exists drop_search('gif') %>% select(path, is_dir, mime_type) ## End(Not run)
This function will allow you to write files of any size to Dropbox(even ones that cannot be read into memory) by uploading them in chunks.
drop_upload( file, path = NULL, mode = "overwrite", autorename = TRUE, mute = FALSE, verbose = FALSE, dtoken = get_dropbox_token() )
drop_upload( file, path = NULL, mode = "overwrite", autorename = TRUE, mute = FALSE, verbose = FALSE, dtoken = get_dropbox_token() )
file |
Relative path to local file. |
path |
The relative path on Dropbox where the file should get uploaded. |
mode |
- "add" - will not overwrite an existing file in case of a conflict. With this mode, when a a duplicate file.txt is uploaded, it will become file (2).txt. - "overwrite" will always overwrite a file - |
autorename |
This logical determines what happens when there is a conflict. If true, the file being uploaded will be automatically renamed to avoid the conflict. (For example, test.txt might be automatically renamed to test (1).txt.) The new name can be obtained from the returned metadata. If false, the call will fail with a 409 (Conflict) response code. The default is 'TRUE' |
mute |
Set to FALSE to prevent a notification trigger on the desktop and mobile apps |
verbose |
By default verbose output is |
dtoken |
The Dropbox token generated by |
## Not run: write.csv(mtcars, file = "mtt.csv") drop_upload("mtt.csv") ## End(Not run)
## Not run: write.csv(mtcars, file = "mtt.csv") drop_upload("mtt.csv") ## End(Not run)