FolioReader-Android icon indicating copy to clipboard operation
FolioReader-Android copied to clipboard

Read epub without saving in local storage

Open munnadroid opened this issue 4 years ago • 3 comments

Feature - Read epub without saving in local storage FolioReader version - 0.5.4 Android SDK - 28

I can see the FR can only epub file from assets, raw or file path from storage. I can also see that FR library is saving epub in temp location in external storage.

Is there any way to read an epub file without saving in the temp location?

Restrict the epub file access to the current application only. Maybe encrypt the epub file and pass the encrypted epub file path to FR.

munnadroid avatar Mar 29 '20 11:03 munnadroid

Feature - Read epub without saving in local storage FolioReader version - 0.5.4 Android SDK - 28

I can see the FR can only epub file from assets, raw or file path from storage. I can also see that FR library is saving epub in temp location in external storage.

Is there any way to read an epub file without saving in the temp location?

Restrict the epub file access to the current application only. Maybe encrypt the epub file and pass the encrypted epub file path to FR.

or from inputStream

YohannesGetu avatar Apr 23 '20 10:04 YohannesGetu

@munnadroid as a workaround, you can do the following:

  1. request permissions: (Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)
  2. I guess your source comes from network, so you may use something like this: val targetPath = context.getExternalFilesDir(null)+ "/temp_dir/temp_file.epub" "https://path.to.epub".saveTo(targetPath)

Folioreader.get().openBook(targetPath)

private fun String.saveTo(path: String) {
        URL(this).openStream().use { input ->
            FileOutputStream(File(path)).use { output ->
                input.copyTo(output)
            }
        }
    }
  1. last part is cleanup - during usage you already created a file on device: val tempFIle = File(targetPath) then, remove file using tempFile.delete() if no longer needed, ortempFile.deleteOnExit()(removes file when virtual machine is terminated) make sure during file operations to close all streams, otherwise delete could won't work: https://stackoverflow.com/questions/24758520/deleteonexit-not-deleting-file/28751091

Marchuck avatar May 17 '20 20:05 Marchuck

@munnadroid as a workaround, you can do the following:

  1. request permissions: (Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)
  2. I guess your source comes from network, so you may use something like this: val targetPath = context.getExternalFilesDir(null)+ "/temp_dir/temp_file.epub" "https://path.to.epub".saveTo(targetPath)

Folioreader.get().openBook(targetPath)

private fun String.saveTo(path: String) {
        URL(this).openStream().use { input ->
            FileOutputStream(File(path)).use { output ->
                input.copyTo(output)
            }
        }
    }
  1. last part is cleanup - during usage you already created a file on device: val tempFIle = File(targetPath) then, remove file using tempFile.delete() if no longer needed, ortempFile.deleteOnExit()(removes file when virtual machine is terminated) make sure during file operations to close all streams, otherwise delete could won't work: https://stackoverflow.com/questions/24758520/deleteonexit-not-deleting-file/28751091

yes, but it can be accessed by a user with root access, like rooted phones

YohannesGetu avatar May 17 '20 21:05 YohannesGetu