react-native-blob-util icon indicating copy to clipboard operation
react-native-blob-util copied to clipboard

[Error: Unexpected FileStorage response file: null]

Open valery-lavrik opened this issue 11 months ago • 3 comments

I'm trying to download a file, and everything is working fine. But there is one address that takes a long time to generate this file before uploading it. It lasts about 12 minutes. And at the moment when the file comes in response, I get an error - Unexpected FileStorage response file: null I repeat, only when the wait is 12 minutes or more...

What can be done?

Android 15 "react": "18.3.1", "react-native": "0.76.5", "react-native-blob-util": "^0.19.8",

try {
    const res = await ReactNativeBlobUtil.config({
        path,
        trusty: true,
        fileCache: false,
        overwrite: true,
        timeout: (1000 * 500),
    }).fetch('GET',
        url,
        {
            Authorization: 'Bearer ' + token,
        }
    ).progress((received, total) => {
        console.log(received, total);
    });

    if (res.respInfo.status !== 200) {
        throw new Error(await res.text());
    }
} catch (error: any) {
    console.log(error); // [Error: Unexpected FileStorage response file: null]
}

valery-lavrik avatar Jan 17 '25 11:01 valery-lavrik

@valery-lavrik what's the path used? In my case it was failing because Android wanted to create the folder to store the file but I passed "file://........./file.mp3" to the path. So I had to remove the "file://" so the library can create the folder.

smfunder avatar Jan 20 '25 06:01 smfunder

@valery-lavrik какой путь используется? В моем случае это не работало, потому что Android хотел создать папку для хранения файла, но я передал в путь «file://........./file.mp3». Поэтому мне пришлось убрать «file://», чтобы библиотека могла создать папку.

const path = ReactNativeBlobUtil.fs.dirs.CacheDir + '/sync.file';

valery-lavrik avatar Jan 20 '25 06:01 valery-lavrik

@valery-lavrik какой путь используется? В моем случае это не работало, потому что Android хотел создать папку для хранения файла, но я передал в путь «file://........./file.mp3». Поэтому мне пришлось убрать «file://», чтобы библиотека могла создать папку.

const path = ReactNativeBlobUtil.fs.dirs.CacheDir + '/sync.file';

@valery-lavrik ok, that seems to be good related to the "file://" prefix. What I had to do is to debug the app with Android Studio and add some Log.d to the ReactNativeBlobUtilReq.java file, I was able to find that there was an error thrown when creating the extended responseBody (line 556) causing the future "null" error. You may be able to debug that way on your side and detect the original issue. In my case I also had to pre-create the folder where I would store my file with:

  /**
   * Get the base path for storing cached audio messages
   * @returns string with the path pointing to the cached audio folder
   */
  const getAudioCacheFolderPath = () => {
    return `${RNFS.CachesDirectoryPath}/audios/`
  }

  /**
   * Prepare the path for audio cache creating the directory
   */
  const prepareAudioCacheFolderPath = async () => {
    const folderPath = getAudioCacheFolderPath()
    try {
      // Check if the directory exists
      const exists = await RNFS.exists(folderPath)

      if (!exists) {
        // Create the directory
        await RNFS.mkdir(folderPath)
        console.log(`+ PlayerContext - Cache Audio Directory created at: ${folderPath}`)
      } else {
        console.log(`+ PlayerContext - Cache Audio Directory already exists at: ${folderPath}`)
      }
    } catch (error) {
      console.error(`+ PlayerContext - Error preparing audio cache folder: ${error.message}`)
      addSentryBreadcrumb({}, SENTRY_LEVEL.error, 'Cannot create cache audio folder at ' + folderPath)
      Sentry.captureException(error)
    }
  }

smfunder avatar Jan 20 '25 06:01 smfunder

Any suggestions for improvements on your side since seems like you found a way to get it to work?

RonRadtke avatar Apr 12 '25 07:04 RonRadtke

Any suggestions for improvements on your side since seems like you found a way to get it to work?

I just wrote this function in my own module and use it. It works perfectly

valery-lavrik avatar Apr 13 '25 06:04 valery-lavrik