question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying to download to path

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
anggrayudicommented, Jan 18, 2021

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.

0reactions
DavidKmncommented, Jan 16, 2021

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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found