[英]Download manager downloads a bin file if file name not specified (Google Cloud Storage URL)
我有一個Google Cloud Storage下載鏈接,並且我正在使用Android DownloadManager下載該文件,當我在未指定文件名的情況下下載文件時,最終會下載.bin文件。
還有一件事是:如果我嘗試從chrome瀏覽器手動下載鏈接,則可以正常工作。
fun downloadFile() {
val uri = Uri.parse("...") //link to the file
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
.mkdirs()
val request =
DownloadManager.Request(uri)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
//.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "file.jpg")
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
downloadID = downloadManager.enqueue(request)
}
通常,對於HTTP,要使用所需的文件名下載文件,服務器必須將Content-Disposition
標頭設置為attachment; filename="filename.jpg"
attachment; filename="filename.jpg"
。 可以在帶有元數據的 GCS中進行設置。 通過這種方式設置內容處置之后,DownloadManager在選擇文件名時應遵循該規定。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.