R Dropbox文件下载 [英] R Dropbox File Download

查看:94
本文介绍了R Dropbox文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个共享给我下载的保管箱链接,但与其他链接不同,它说我被禁止下载。

I have a dropbox link that was shared to me to download but unlike other link, its says I am forbidden to download it.

我的功能:

source_DropboxData <- function(file, key, sha1 = NULL, sep = ",", header = TRUE){
  URL <- paste0('https://dl.dropboxusercontent.com/s/', 
            key, '/', file)

  stopifnot(is.character(URL), length(URL) == 1)

  temp_file <- tempfile()
  on.exit(unlink(temp_file))

  request <- GET(URL)
  stop_for_status(request)
  writeBin(content(request, type = "raw"), temp_file)

  file_sha1 <- digest(file = temp_file, algo = "sha1")

  if (is.null(sha1)) {
    message("SHA-1 hash of file is ", file_sha1)
  }
  else {
    if (!identical(file_sha1, sha1)) {
      stop("SHA-1 hash of downloaded file (", file_sha1, 
       ")\n  does not match expected value (", sha1, 
           ")", call. = FALSE)
    }
  }

  read.table(temp_file, sep = sep, header = header)
}    

我的链接如下:

https://www.dropbox.com/sh/od6ymc4wu8uht5e/IxPX-EOhNx/a%b%x  #fake, for demonstration

正式的看起来像这样:

http://dl.dropbox.com/s/c18lcwnnrodsevt/test_dropbox_source.R

我的问题是两个链接之间有什么区别,一个是安全的,不能下载,而另一个有可能吗我的印象是,repmis的功能既可以处理私有文件,也可以处理公共文件。

My question is whats the difference between the two link, is one secure and not downloadable while another is possible? I was under the impression that the function from repmis is able to do both private and public files.

谢谢

推荐答案

这里的关键是


  1. tell dropbox通过在URL后面附加?raw = 1 来提供原始文件>
  2. 由于保管箱使用https,因此您(目前至少)需要打开连接(足够聪明以使用安全传输)并将此连接提供给文件读取或加载功能(不仅仅是原始文件) URL字符串)

  1. tell dropbox to serve up the raw file by appending ?raw=1 to the URL
  2. as dropbox uses https, you (currently at least) need to open the connection (which is smart enough to use secure transport) and give this connection to the file read or load function (not just a raw URL string)

此示例使用 load .rda 文件,但对于 read.csv 等也适用。

This is an example using load and a .rda file, but same works for read.csv etc.

myURL = "https://www.dropbox.com/s/randomIDstring/YourFilename.rda?raw=1"
myConnection = url(myURL)
print(load(myConnection))
close(myConnection) # good practice to close connection opened by url()

这篇关于R Dropbox文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆