PUT new media into a Drive file

PUTs new media into a Drive file, in the HTTP sense: if the file already exists, we replace its content and we create a new file, otherwise. This is a convenience wrapper around drive_upload() and drive_update(). In pseudo-code:

target_filepath <- <determined from `path`, `name`, and `media`>
hits <- <get all Drive files at target_filepath>
if (no hits) {
  drive_upload(media, path, name, type, ..., verbose)
} else if (exactly 1 hit) {
  drive_update(hit, media, ..., verbose)
} else {

drive_put(media, path = NULL, name = NULL, ..., type = NULL,
  verbose = TRUE)

Character, path to the local file to upload.


Specifies target destination for the new file on Google Drive. Can be an actual path (character), a file id marked with as_id(), or a dribble. If specified as an actual path, it is best to explicitly indicate if it's a folder by including a trailing slash, since it cannot always be worked out from the context of the call. Will default to its local name.


Character, new file name if not specified as part of path. This will force path to be treated as a folder, even if it is character and lacks a trailing slash. Will default to its local name.


Named parameters to pass along to the Drive API. Has the tidy dots semantics that come from using rlang::list2(). You can affect the metadata of the target file by specifying properties of the Files resource via .... Read the "Request body" section of the Drive API docs for the associated endpoint to learn about relevant parameters.


Character. If type = NULL, a MIME type is automatically determined from the file extension, if possible. If the source file is of a suitable type, you can request conversion to Google Doc, Sheet or Slides by setting type to document, spreadsheet, or presentation, respectively. All non-NULL values for type are pre-processed with drive_mime_type().


Logical, indicating whether to print informative messages (default TRUE).


An object of class dribble, a tibble with one row per item.

  • drive_put
# create a local file to work with
local_file <- tempfile("drive_put_", fileext = ".txt")
writeLines(c("beginning", "middle"), local_file)

# PUT to a novel filepath --> drive_put() delegates to drive_upload()
file <- drive_put(local_file)

# update the local file
cat("end", file = local_file, sep = "\n", append = TRUE)

# PUT again --> drive_put() delegates to drive_update()
file <- drive_put(local_file)

# create a second file at this filepath
file2 <- drive_create(basename(local_file))

# PUT again --> ERROR

# clean-up
drive_find("drive_put_.+[.]txt") %>% drive_rm()
# }
Documentation reproduced from package googledrive, version 1.0.0, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.