Trying to download to path
See original GitHub issueI’m trying to use a library like Fetch (https://github.com/tonyofrancis/Fetch) to download: photos, videos, audios and documents to the filesystem. What is the correct way to generate a path for simple storage to download to?
findViewById<FloatingActionButton>(R.id.fab).setOnClickListener {
val tsLong = System.currentTimeMillis() / 1000
val ts = tsLong.toString()
val url = "https://unsplash.com/photos/FQq88kJLoyI/download?force=true"
val mediaFile = MediaStoreCompat.createImage(this, FileDescription("image${ts}.jpg", subFolder = "Bramti Images", mimeType = "image/jpg"), ImageMediaDirectory.PICTURES)
// val intent = Intent(applicationContext, DownloadService::class.java)
// intent.putExtra("downloadUrl", url)
val path = mediaFile!!.absolutePath
// intent.putExtra("saveFilePath", path)
enqueueDownload(url, path)
}
}
private fun enqueueDownload(url: String, filePath: String) {
request = Request(url, filePath)
fetch.attachFetchObserversForDownload(request.id, this)
.enqueue(request, { result -> request = result }, { result -> Log.d("MainActivity", "SingleDownloadActivity Error: %1${result}s") })
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Download a file - Computer - Google Chrome Help
On your computer, open Chrome. Go to the webpage where you want to download the file. Save the file: Most files: Click on...
Read more >11 Ways to Fix "The System Cannot Find The Path Specified ...
8. Check for Incomplete Downloads ... Ensure that the file or folder you are trying to access has been installed or downloaded correctly....
Read more >"Windows cannot access the specified device, path, or file ...
Check the path of the file that Windows cannot access and make sure that the location is accessible. (The screen shot for this...
Read more >Change default download location in window PC ... - YouTube
How to Change Download Location in Windows 10/8.1/7. 487,146 views487K views. Oct 8, 2016.
Read more >How To Change Download Location / Ask Where to Save in ...
By turning it on, Chrome will ask you where to save the downloaded files each time you try to download something.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
DocumentFileCompat.from...()
returns null if you have no URI access. You had better cloning this project and test the code on your own. I will close this issue since the discussion becoming more complex and I have no much time to teach you.I’ll write the documentation, but not for now since this library is still in big development.
What if I just wanted to create a file in the Environment.DIRECTORY_DOCUMENTS and then write to its uri. I tried (after giving access) this:
DocumentFileCompat.fromPublicFolder(this, PublicDirectory.DOWNLOADS, subFile = "doc${ts}.pdf", requiresWriteAccess = true)
however this returns null (it does not return null if I omit the subFile parameter, but then I am unclear on how and where to name the file)