有沒有辦法迫使一個下載鏈接,而不是瀏覽器試圖打開該文件?在這種情況下,我有一個文檔電子表格和一些指向mp3文件的鏈接。我希望用戶下載這些文件,而不是瀏覽器播放它。這些mp3被託管在另一個網站上。 感謝,博強制下載鏈接
強制下載鏈接
回答
要下載鏈接的文檔 - https://docs.google.com/feeds/download/documents/Export?docID=yourDocId
要下載鏈接的任何文件 - https://docs.google.com/uc?id=yourDocId&export=download&hl=en_US
要下載鏈接的電子表格 - https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=yourDocId&exportFormat=csv
爲了進一步信息,請訪問here
正在更新2018
新下載網址是
https://docs.google.com/spreadsheets/d/<KEY>/export?gid=<GID>&format=csv
其中<KEY>
和<GID>
可以從導航的URL獲得,
https://docs.google.com/spreadsheets/d/<KEY>/edit#gid=<GID>
PS:試算表可能多個工作簿,GID是所希望的工作簿ID。一工作簿,電子表格通常有gid=0
,但如果你添加更多的他們將有隨機數(該GID是preseved甚至改變標籤順序)。
因此,使用wget
或curl
可以測試,
wget --no-check-certificate -O test.csv \
'https://docs.google.com/spreadsheets/d/0At2sqNEgxTf3dEt5SXBTemZZM1gzQy1vLVFNRnludHc/export?gid=0&format=csv'
該鏈接爲「對任何文件下載鏈接」被打破了。更新? – 2011-09-11 15:45:34
這些鏈接現在怎麼樣? – Defozo 2016-02-18 23:32:46
要在Mokarom的答案擴大(因爲我不能評論)您需要使用,以取代那些說「yourDocId」鏈接的部分您嘗試下載的網頁的文檔ID。這是url的關鍵部分。
例如,如果您有一個電子表格https://docs.google.com/spreadsheet/ccc?key=0AhjOs40Xk1-4dGg0MjMVYURPMFRpeUFhbmZBTkZ0dEE#gid=8,那麼您將轉至https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=0AhjOs40Xk1-4dGg0MjMVYURPMFRpeUFhbmZBTkZ0dEE&exportFormat=csv下載鏈接。
在我的應用程序,我需要在一個CSV文件(逗號分隔值)的形式 下載谷歌驅動器的電子數據表。谷歌驅動器中的文件被長ID的引用,如:
1uFwmwD5UFLdD1DMPGT5p4fIGozfImx44DNCOeMJr1Lo
下面是一個代碼塊,將做到這一點。如果出現錯誤,該方法將返回一個零長度的字符串。
- (NSString *) downloadGoogleSheetGivenFileID: (NSString *) ID {
// This will download a Google spreadsheet given it's file ID
// and convert it to a CSV file.
NSString * preFix;
NSURL * myURL;
NSString * opCmd;
NSString * t;
NSString * theStuff;
NSError * error = nil;
theStuff = @"";
// The URL has to be: prefix+ID+opCmd The only thing that changes is the file's ID
preFix = @"https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=";
opCmd = @"&exportFormat=csv";
t = preFix;
t = [t stringByAppendingString:ID];
t = [t stringByAppendingString:opCmd];
myURL = [NSURL URLWithString:t];
theStuff = [NSString stringWithContentsOfURL:myURL encoding: NSUTF8StringEncoding error:&error];
if(error != nil)
{
// There was an error downloading the spread sheet file.
// We will return a zero length string.
NSLog(@"%@",error);
}
return theStuff;
}
添加標籤讓相關人員瞭解您的問題。 – dosdebug 2017-10-21 19:10:58
- 1. 強制下載在FTP://鏈接
- 2. 強制下載
- 3. 強制下載的Safari鏈接與內容處置MP3鏈接:內嵌
- 4. 如何強制在鏈接上完全下載txt文件?
- 5. 如何強制在Chrome中打開鏈接不下載它們
- 6. 如何強制下載鏈接在GridView內的文件?
- 7. 調整圖像大小後強制下載鏈接
- 8. 強制瀏覽器使用jquery點擊鏈接下載圖片
- 9. 使用javascript/ajax/jquery強制下載pdf鏈接
- 10. 強制Grails重製鏈接
- 11. PHP強制下載
- 12. 強制下載ASP.Net
- 13. 下載鏈接
- 14. 下載鏈接
- 15. 強制下載流 - 強制下載excel文件
- 16. 如何強制用戶登錄以下載文檔,直接鏈接到文檔?
- 17. 強制鏈接使用laravel
- 18. 強制鏈接到iframe
- 19. 創建下載限制鏈接
- 20. jslint.js下載鏈接
- 21. Grails下載鏈接
- 22. 下載鏈接HTML
- 23. Wicket下載鏈接
- 24. Javascript下載鏈接
- 25. cakePHP強制下載文件
- 26. 強制下載文件
- 27. 強制在php下載
- 28. 如何強制下載
- 29. php:強制下載到hd?
- 30. 防止強制下載
這就像yihaaa! – 2011-05-26 14:22:16
所以沒有人對這類問題感興趣吧?你應該 – 2011-05-26 18:00:26