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.

FIleSystem.copyAsync not copying full video to cacheDirectory on IOS

See original GitHub issue

🐛 Bug Report

Summary of Issue

Using FileSystem.copyAsync to copy videos on IOS from assets-library:// to file:// uri for uploading, videos are not copied successfully. FileSystem.getInfoAsync on the new file returns wrong file size and videos fail to upload as they appear corrupted.

Environment

Expo CLI 3.27.7 environment info: System: OS: macOS 10.15.7 Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node Yarn: 1.22.5 - /usr/local/bin/yarn npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2 IDEs: Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild npmPackages: @expo/webpack-config: ^0.12.16 => 0.12.29 expo: ^38.0.0 => 38.0.10 react: 16.11.0 => 16.11.0 react-dom: 16.11.0 => 16.11.0 react-native: https://github.com/expo/react-native/archive/sdk-38.0.0.tar.gz => 0.62.2 react-native-web: ~0.11.7 => 0.11.7 react-navigation: ^4.3.9 => 4.4.0 Expo Workflow: managed

Steps to Reproduce

          const newFileUri = FileSystem.cacheDirectory + file.filename // video.mov
          FileSystem.copyAsync({
            from: file.uri,
            to: newFileUri,
          }).then(() => {
            FileSystem.getInfoAsync(newFileUri, { size: true }).then(
              (asset) => {
                if (asset.exists) {
                  console.log('file saved from asset. . . : ', asset)
               }
            })

Expected Behavior vs Actual Behavior

Video is 30mb+ and resulting asset is only 300kb give or take. Expect resulting asset from the copy to be full video/size, and to be able to be uploaded, not corrupt.

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jiantongccommented, Mar 21, 2021

There’s a workaround you can try, note that I’ve only tested on iOS with Expo 40.0, expo-file-system 9.3.0, and expo-media-library 10.0.0.

 // Asset retrieved from MediaLibrary 
// https://docs.expo.io/versions/latest/sdk/media-library/#asset
const {filename, uri} = asset;

try {
     // This doesn't work ---->
     // await FileSystem.copyAsync({
     //    from: uri,
     //    to: `${FileSystem.documentDirectory}${filename}`,
     //   });

     // Get the uri with file:// prefix
      const {localUri} = await MediaLibrary.getAssetInfoAsync(asset);
      if (!localUri) { // You can ignore this checking if you want
        throw 'Empty localUri';
      }
      await FileSystem.copyAsync({
        from: localUri,
        to: `${FileSystem.documentDirectory}${filename}`,
      });
} catch (e) {
    // error handling
}

0reactions
stale[bot]commented, Jul 20, 2021

This issue has been automatically closed since there has not been any recent activity after it was marked as stale. Please open a new issue for any related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FileSystem - Expo Documentation
Create a copy of a file or directory. Directories are recursively copied with all of their contents. It can be also used to...
Read more >
How to Save Files to a Device Folder using Expo and React ...
Save files to a device's internal storage so that it's publicly visible to other apps with one line of code.
Read more >
expo-file-system - npm
Start using expo-file-system in your project by running `npm i ... Directories are recursively copied with all of their contents.
Read more >
Expo FileSystem.moveAsync location is not moveable?
Expo's FileSystem module can copy/move/etc. files that are previously saved in the app's scope (for example via ImagePicker or using Asset.
Read more >
Expo FileSystem.cacheDirectory must be cleaned manually.
So, here is the dilemma -- I can't expect my customers to re-instal the app every couple of weeks, but I can't serve...
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