سؤال

This question is related to the my previous question reading raw data in R to be saved as .RData file using the dropbox api

I am running into problems when my path includes non-url standard characters

the db.file.name in the previous question is just the path to the relevant file in dropbox.

however the path has a space in it along with exclamation marks. I have a feeling that these need to be converted to a relevant format so that the GET request can work...but not too sure what the conversion is....

so using and continuing from my previous example...

require(httr)
require(RCurl)
db.file.name <- "!! TEST FOLDER/test.RData"
db.app <- oauth_app("db",key="xxxxx", secret="xxxxxxx")
db.sig <- sign_oauth1.0(db.app, token="xxxxxxx", token_secret="xxxxxx")

response <- GET(url=paste0("https://api-content.dropbox.com/1/files/dropbox/",curlEscape(db.file.name)),config=c(db.sig,add_headers(Accept="x-dropbox-metadata")))

The response is an error, and no file is downloaded...using the documentation page https://www.dropbox.com/developers/reference/api it suggests putting the URL into a UTF-8 encoding...which I'm not sure how to do/not sure it works.

Any help would be greatly appreciated.

هل كانت مفيدة؟

المحلول

I was close before...I just needed to re-insert the slashes using gsub in order for the GET request to work... so the result was

response <- GET(url=paste0("https://api-content.dropbox.com/1/files/dropbox/",gsub("%2F","/",curlEscape(db.file.name))),config=c(db.sig,add_headers(Accept="x-dropbox-metadata")))

نصائح أخرى

the quick copy-past from ?iconv,

x <- "fa\xE7ile"
Encoding(x) <- "latin1"
charToRaw(xx <- iconv(x, "latin1", "UTF-8"))
[1] 68 74 74 70 3a 2f 2f 73 74 61 63 6b 6f 76 65 72 66 6c 6f 77 2e 63 6f 6d
Encoding(x)
[1] "latin1"
Encoding(xx)
[1] "UTF-8"

does this answer your question?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top