Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileNotFound Exception while unzipping the file in Android #311

Open
Praveencena88 opened this issue Jul 30, 2024 · 5 comments
Open

FileNotFound Exception while unzipping the file in Android #311

Praveencena88 opened this issue Jul 30, 2024 · 5 comments

Comments

@Praveencena88
Copy link

Describe the bug
Whenever i try to unzip file to a specific destination using unZip function, It throws the warning fileNotfound. when i checked for the zip file in the respective path, it's present in the file system.

image

React-Native : 0.63.3
react-native-zip-archive: 7.0.0

@plrthink
Copy link
Collaborator

plrthink commented Aug 9, 2024

Can you attach the file you're using? It's hard to tell what's going wrong without the file and the code.

@cedced19
Copy link

cedced19 commented Aug 25, 2024

Same here.
Error: Failed to extract file java.io.FileNotFoundException: /data/user/0/com.lesbaladesdedecouverto/files/decouverto/PNDXGzA/images/74PMrHw.jpg: open failed: EACCES (Permission denied)]

@ryanshepps
Copy link

ryanshepps commented Mar 11, 2025

Any updates on this? Currently getting the same error (ENOENT).

java.io.FileNotFoundException: /storage/emulated/0/Download/canada.zip: open failed: ENOENT (No such file or directory): Error: java.io.FileNotFoundException: /storage/emulated/0/Download/canada.zip: open failed: ENOENT (No such file or directory)

It's only happening on some phones for me (e.g., Samsung Galaxy S24 Ultra). With other Android and iOS apps the zip completes successfully. Here is an example of the code I'm running with logs:

export const zipFile = async (sourcePath: string, targetPath: string) => {
  try {
    const fileExists = await RNFS.exists(sourcePath);
    LoggerService.info(`fileExists: ${fileExists}`);

    const targetFileExists = await RNFS.exists(targetPath);
    LoggerService.info(`targetFileExists: ${targetFileExists}`);

    LoggerService.info(`readdir: ${await RNFS.readdir(sourcePath)}`);

    return await zip(sourcePath, targetPath);
  } catch (error: any) {
    LoggerService.error(`Unable to create zip at ${targetPath} src=${sourcePath}`, error);
    throw error;
  }
};
2025-03-11T16:29:25.239Z [INFO] fileExists: true 
2025-03-11T16:29:25.240Z [INFO] targetFileExists: false 
2025-03-11T16:29:25.244Z [INFO] readdir: Canada_PROPERTY_DETAILS.pdf 
2025-03-11T16:29:25.257Z [ERROR] Unable to create zip at /storage/emulated/0/Download/canada.zip src=/storage/emulated/0/Documents/ValueConnect/canada java.io.FileNotFoundException: canada.zip: open failed: ENOENT (No such file or directory): Error: java.io.FileNotFoundException: /storage/emulated/0/Download/canada.zip: open failed: ENOENT (No such file or directory)
    at promiseMethodWrapper (address at index.android.bundle:1:73311)
    at zip (address at index.android.bundle:1:1951499)
    at ?anon_0_ (address at index.android.bundle:1:1950277)
    at next (native)
    at asyncGeneratorStep (address at index.android.bundle:1:534092)
    at _next (address at index.android.bundle:1:534349)
    at tryCallOne (/root/react-native/packages/react-native/ReactAndroid/hermes-engine/.cxx/MinSizeRel/3v1xb2f2/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:53:16)
    at anonymous (/root/react-native/packages/react-native/ReactAndroid/hermes-engine/.cxx/MinSizeRel/3v1xb2f2/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:139:27)
    at apply (native)
    at anonymous (address at index.android.bundle:1:190672)
    at _callTimer (address at index.android.bundle:1:189623)
    at _callReactNativeMicrotasksPass (address at index.android.bundle:1:189767)
    at callReactNativeMicrotasks (address at index.android.bundle:1:191762)
    at __callReactNativeMicrotasks (address at index.android.bundle:1:77487)
    at anonymous (address at index.android.bundle:1:76570)
    at __guard (address at index.android.bundle:1:77325)
    at flushedQueue (address at index.android.bundle:1:76481)
    at invokeCallbackAndReturnFlushedQueue (address at index.android.bundle:1:76424)

@cedced19
Copy link

cedced19 commented Mar 11, 2025 via email

@ryanshepps
Copy link

It appears the issue is with net.lingala.zip4j.zip4j. I compiled react-native-zip-archive locally with my own logs and was able to get the following stack trace:

net.lingala.zip4j.exception.ZipException: java.io.FileNotFoundException: /storage/emulated/0/Download/canada.zip: open failed: ENOENT (No such file or directory)
at net.lingala.zip4j.tasks.AsyncZipTask.performTaskWithErrorHandling(AsyncZipTask.java:58)
at net.lingala.zip4j.tasks.AsyncZipTask.execute(AsyncZipTask.java:45)
at net.lingala.zip4j.ZipFile.addFiles(ZipFile.java:319)
at net.lingala.zip4j.ZipFile.addFile(ZipFile.java:276)
at com.rnziparchive.RNZipArchiveModule$4.run(RNZipArchiveModule.java:411)
at java.lang.Thread.run(Thread.java:1012)
Caused by: java.io.FileNotFoundException: /storage/emulated/0/Download/canada.zip: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:574)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:289)
at net.lingala.zip4j.io.outputstream.SplitOutputStream.<init>(SplitOutputStream.java:51)
at net.lingala.zip4j.tasks.AbstractAddFileToZipTask.addFilesToZip(AbstractAddFileToZipTask.java:66)
at net.lingala.zip4j.tasks.AddFilesToZipTask.executeTask(AddFilesToZipTask.java:33)
at net.lingala.zip4j.tasks.AddFilesToZipTask.executeTask(AddFilesToZipTask.java:20)
at net.lingala.zip4j.tasks.AsyncZipTask.performTaskWithErrorHandling(AsyncZipTask.java:51)
... 5 more

Unfortunately I do not understand zip4j enough to continue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants