0

I'm building a react native expo app that uses expo camera to take short videos and uses expo-av to replay them for the user. When I first open the app it works fine, but when I background the app and then reopen it (bring it back to the foreground) and try to take a video, I get an error that the file cannot be copied to the cache.

File 'file:///var/mobile/Containers/Data/Application/D31F9699-9FB1-4C26-BCDD-0D693243D555/Library/Caches/Camera/41C1BC53-CFEE-4163-9FAB-16252A7230FB.mov' could not be copied to 'file:///var/mobile/Containers/Data/Application/D31F9699-9FB1-4C26-BCDD-0D693243D555/Library/Caches/1681222984251.mp4'.

I'm not sure why expo-file-system seems to be locked out of the local cache on iOS, but if there's any way around this please let me know. Here is my load video method:

`const loadVideo = async (data) => {

setLoading(true)

// Set a timeout of 10 seconds
const timeout = setTimeout(async () => {
  setLoading(false);
  setLoadingError(true);
}, 10000);


// Get the URI of the video file from the data object returned by recordAsync
const videoUri = data.uri;

// Generate a unique filename for the video file in the cache
const filename = `${Date.now()}.mp4`
const cacheUri = `${FileSystem.cacheDirectory}${filename}`

// Copy the video file to the local cache
await FileSystem.copyAsync({
  from: videoUri,
  to: cacheUri,
})

// Check if the video file exists in the cache
const fileInfo = await FileSystem.getInfoAsync(cacheUri)
if (fileInfo.exists) {
  console.log('Video file exists in cache.')
  userVideo.uri = cacheUri
  setVideoAdded(false)
  setShowVideo(true)
  clearTimeout(timeout);
} else {
  console.log('Video file does not exist in cache.')
}

setLoading(false)

}`

I'm using expo SDK 47.0.0 and react native 0.70.8. My expo-file-system version is "~15.1.1"

I've also tried creating a new cache directory using expo-file-system, but I still get an error saying that the new directory could not be created.

Directory 'file:///var/mobile/Containers/Data/Application/D31F9699-9FB1-4C26-BCDD-0D693243D555/Library/Caches/my-cache-directory' could not be created.

0 Answers0