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

[Error: Unexpected FileStorage response file: null] on android 14 #363

Open
YASH6004 opened this issue May 24, 2024 · 6 comments
Open

[Error: Unexpected FileStorage response file: null] on android 14 #363

YASH6004 opened this issue May 24, 2024 · 6 comments

Comments

@YASH6004
Copy link

Hi,

- Steps to replicate the issue

  1. Grant permission to the app
  2. download the data with the given code [it will download the zip file from the URL using cookie-based authentication ]
  3. now delete the created folder from android > download > ${filename} [ delete the whole folder ]
  4. now try to download again it will throw this error but this will create the folder ${filename}
  • Screenshot 2024-05-24 at 1 52 25 PM
  • RN version
    "react": "18.1.0",
    "react-native": "0.70.6",

  • android version 14
    Device Samsung s23 ultra

*here is my code sinnpet '''
export const exportClientData = async (type: 'all' | 'single', client_id?: string) => {
let filepath = '';
let url = '';

if (type === 'all') {
url = https://...;
} else if (type === 'single') {
url = https:///.......;
}

// Get the app's cache directory
const { fs } = ReactNativeBlobUtil;
const cacheDir = Platform.OS === 'ios' ? fs.dirs.DocumentDir : fs.dirs.LegacyDownloadDir;

// Define the filename
const filename = 'filename';

// Construct the full filepath
if (type === 'all') {
filepath = ${cacheDir}/${filename}/ClientData.zip;
} else if (type === 'single') {
filepath = ${cacheDir}/${filename}/${client_id}.zip;
}

try {
// // Ensure the directory exists
// const dirPath = ${cacheDir}/${filename};
// const isDir = await fs.isDir(dirPath); // Check if the directory exists

  // if (!isDir) {
  //     await fs.mkdir(dirPath); // Create the directory if it does not exist
  // }

  // Download the file and save it to the cache directory
  const configOptions:any = Platform.select({
      ios: {
          fileCache: true,
          path: filepath,
          appendExt: 'zip',
      },
      android: {
          fileCache: true,
          path: filepath,
          appendExt: 'zip',
      },
  });

  const response = await ReactNativeBlobUtil.config(configOptions).fetch('GET', url, {
      "Accept": "*/*",
      "Accept-Encoding": "*/*",
  });
  console.log('response==>>', JSON.stringify(response, undefined, 4));
  return response;

} catch (error) {
console.error('error in downloading==>', error);
return error;
}
};
'''

@YASH6004
Copy link
Author

YASH6004 commented Jun 4, 2024

any update anyone?

@topheroes
Copy link

@YASH6004 Facing the same problem. Did you solve it?

@valery-lavrik
Copy link

I'm getting a similar problem. Is there a solution?
The problem is reproduced when the file download request lasts more than 10 minutes.

@smfunder
Copy link

In my case I found that in the path parameter of config I should not include the "file://" prefix because that would make the library fail to create the container folder crashing the interceptor that later will be seen as "null" because it cannot be casted due the unhandled error.

@Eclipses-Saros
Copy link

I'm also getting a same problem. but somehow I've figured out one way to avoid this error: DO NOT USE path option.

android: {
    fileCache: true, // <- if you enable this,
    path: filepath, // <- this cause a weird problem
    appendExt: 'zip',
},

once you have exception with fetch function, somehow BlobUtil fetch went completely wrong and cannot be fixed. I even checked with debugger, only know it will run the native code (ReactNativeBlobUtilReq::run) and suddenly pops out 'Error: Unexpected FileStorage response file: null'.

without path option, how can you move downloaded files to desire destination? use ReactNativeBlobUtil.fs.cp or ReactNativeBlobUtil.MediaCollection.copyToMediaStore. when fileCache option is set to true, you can get the cached file path.

const res = await BlobUtil.config({
  fileCache: true
}).fetch();

await ReactNativeBlobUtil.MediaCollection.copyToMediaStore(
  {
    name: fileName,
    parentFolder: '',
    mimeType: type,
  },
  'Download',
  res.path(), // <- there it is
);

res.flush(); // <- if you complete file action, you can flush it

to summarize up:

  1. Error: Unexpected FileStorage response file: null happens when you have path in config() and fetch() failed. then everything goes bad.
  2. try to copy cached file. this will prevent many unexpected errors.

@valery-lavrik
Copy link

I'm also getting a same problem. but somehow I've figured out one way to avoid this error: DO NOT USE path option.

android: {
fileCache: true, // <- if you enable this,
path: filepath, // <- this cause a weird problem
appendExt: 'zip',
},
once you have exception with fetch somehow BlobUtil fetch went completely wrong and cannot be fixed. I even checked with debugger, only know it will run the native code (ReactNativeBlobUtilReq::run) and suddenly pops out 'Error: Unexpected FileStorage response file: null'.

without path option, how can you move downloaded files to desire destination? use ReactNativeBlobUtil.fs.cp or ReactNativeBlobUtil.MediaCollection.copyToMediaStore. when fileCache option is set to true, you can get the cached file path.

const res = await BlobUtil.config({
fileCache: true
}).fetch();

await ReactNativeBlobUtil.MediaCollection.copyToMediaStore(
{
name: fileName,
parentFolder: '',
mimeType: type,
},
'Download',
res.path(), // <- there it is
);

res.flush(); // <- if you complete file action, you can flush it
to summarize up:

  1. Error: Unexpected FileStorage response file: null happens when you have path in config() and fetch() failed. then everything goes bad.
  2. try to copy cached file. this will prevent many unexpected errors.

Hopefully, after reading this answer, the developers will find and fix the problem.
In the end, it turned out to be easier for me to write my own module that just downloads a file...

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

No branches or pull requests

5 participants