-1

I have this sample curl request:

curl -X POST https://content.dropboxapi.com/2/files/upload \
    --header "Authorization: Bearer fakeaccesstoke12345" \
    --header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Matrices.txt\",\"mode\": \"add\"}" \
    --header "Content-Type: application/octet-stream" \
    --data-binary @local_file.txt

Which I tried translating into httr like this:

httr::POST(
  "https://content.dropboxapi.com/2/files/upload",
  add_headers(Authorization = "Bearer fakeaccesstoke12345", 
              `Dropbox-API-Arg` = paste("{\"path\": \"/folder/", FileName, "\"mode\": \"add\"}", sep = ''),
              `Content-Type` = "Content-Type: application/octet-stream"
              )
  )

This is not working. I'm not sure what the --data-binary is doing either. The docs don't seem to say anything about it so I wonder if this is some standard parameter in HTTP.

The docs for the upload enpoint can be found here if needed.

Community
  • 1
  • 1
jgozal
  • 1,480
  • 6
  • 22
  • 43
  • There's an R package that does dropbox uploads... https://cran.r-project.org/web/packages/rdrop2/index.html – cory Mar 23 '16 at 20:52
  • I know of `rdrop2` but I would prefer to go the HTTP way if possible. – jgozal Mar 23 '16 at 21:11

1 Answers1

2
library(httr)
library(jsonlite)
POST(
  'https://content.dropboxapi.com/2/files/upload',
  add_headers(
    Authorization = "Bearer <token>",
    `Dropbox-API-Arg` = 
      jsonlite::toJSON(
        list(path = "/books.csv", mode = "add", autorename = TRUE, mute = FALSE), 
        auto_unbox = TRUE
      )
  ),
  content_type("application/octet-stream"),
  body = upload_file("books.csv")
)
sckott
  • 5,755
  • 2
  • 26
  • 42