下载自定义文件时file.download中出错 [英] Error in file.download when downloading custom file

查看:399
本文介绍了下载自定义文件时file.download中出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从此网址下载zip文件:

  url1<  -  http:// www。 clinicaltrials.gov/ct2/results?cond=%22acne%22&studyxml=true 

这是我的代码:

  tempZip<  -  tempfile()
download.file(url1,tempZip)

这里是我得到的错误:

 警告信息:
在download.file(url1,tempZip):
下载长度817445!=报告长度200

任何想法?



编辑:好的,在看到agstudy的回复以后,我发现该文件确实正在下载它也似乎是正确的文件大小)。现在的问题是当我尝试解压文件 - 这天文件被损坏。



Maciej,我同意使用.zip扩展名的链接会更好,但是没有办法从本网站获取。

解决方案

好的,我想出了什么是错的。因为这个url最后没有具体的.zip,所以download.file函数不知道使用二进制的下载。此代码解决了这个问题:

  url1 < -  http://www.clinicaltrials.gov/ct2/results?cond= %22acne%22& studyxml = true 
tempZip< - tempfile()
download.file(url1,tempZip,mode =wb)
pre>

如果没有指定模式参数,下载的zip文件将被破坏。


I'm trying to download the zip file from this url:

url1 <- http://www.clinicaltrials.gov/ct2/results?cond=%22acne%22&studyxml=true

Here's my code:

tempZip <- tempfile()
download.file(url1, tempZip)

And here's the error I get:

Warning message:
In download.file(url1, tempZip) :
  downloaded length 817445 != reported length 200

Any ideas?

EDIT: OK, after seeing agstudy's reply below, I found that the file was indeed being downloaded (it also appears to be the correct file size). Now the problem is when I try to unzip the file - it days the file is corrupted.

Maciej, I agree that it would be better to use a link with a .zip extension, however, there's no way to get that from this website.

解决方案

OK, I figured out what was wrong. Because this url does not specifically have ".zip" at the end, the download.file function does not know to use a binary download. This code fixes the problem:

url1 <- http://www.clinicaltrials.gov/ct2/results?cond=%22acne%22&studyxml=true
tempZip <- tempfile()
download.file(url1, tempZip, mode="wb")

If you don't specify the mode argument, the downloaded zip file will be corrupt.

这篇关于下载自定义文件时file.download中出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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