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

Video file Saving in Ios not working #881

Open
hussnainshafiul opened this issue Sep 4, 2024 · 0 comments
Open

Video file Saving in Ios not working #881

hussnainshafiul opened this issue Sep 4, 2024 · 0 comments

Comments

@hussnainshafiul
Copy link

hussnainshafiul commented Sep 4, 2024

I am downloading the video from an ip camera which is downloaded to DocumentDir , and then trying to save in photos (which is working fine on android) but Ios shows error:

"The operation couldn't be completed (PHPhotosErrorDomain error 3302)"

This is my code to download the video:

const handleDownload = async filePath => {
const videoPath = filePath.split('A:')[1].replace(//g, '/');
const vUrl = http://${selectedCamera.ip}/${videoPath};
const {config, fs} = RNFetchBlob;
const downloads = Platform.OS === 'ios' ? fs.dirs.DocumentDir : fs.dirs.DownloadDir;

const tsFilePath = ${downloads}/${videoPath.split('/').pop()};
const mp4FilePath = tsFilePath.replace('.TS', '.mp4');

// Check if the video is already downloaded
const storedDownloads =
JSON.parse(await AsyncStorage.getItem('downloads')) || [];
const isAlreadyDownloaded = storedDownloads.some(
video => video.filePath === mp4FilePath,
);

if (isAlreadyDownloaded) {
Alert.alert(
'Already Downloaded',
'This video has already been downloaded.',
);
return; // Exit the function early
}

// If not downloaded, proceed with download
setTimeout(() => dispatch(DownloadLoader()), 700);

try {
const response = await config({
fileCache: true,
path: tsFilePath,
}).fetch('GET', vUrl)
.progress((received, total) => {
const progress = received / total;
setDownloadProgress(progress); // Update progress
});

await FFmpegKit.execute(-i ${tsFilePath} -c copy ${mp4FilePath});

await fs.unlink(tsFilePath);

/*saving the file in albums */

let savedUri = null;
try {
savedUri = await CameraRoll.save(mp4FilePath, {type: 'video'});
Alert.alert('Saved to Photos ', 'Video has been saved to your Phone Album');
console.log(savedUri);
} catch (saveError) {
Alert.alert(
'Save Failed',
Failed to save video to Photos: ${saveError.message},
);
}

const downloadedVideo = {
name: mp4FilePath.split('/').pop(),
filePath: savedUri,
url: vUrl,
};
dispatch(addToDownloads(downloadedVideo));

storedDownloads.push(downloadedVideo);
await AsyncStorage.setItem('downloads', JSON.stringify(storedDownloads));

console.log(downloadedVideo);

} catch (error) {
Alert.alert('Download Failed', Error: ${error.message});
} finally {
setTimeout(() => dispatch(DownloadLoader(false)), 700);
}
};

issue is not with file extension , it is (.mp4) , checked on android as well
I have given necessary permissions also in info.plist , still I am receiving this error on ios
any solutions? for this

packages:
"react-native": "0.74.2",
"rn-fetch-blob": "^0.12.0",
"@react-native-camera-roll/camera-roll": "^7.8.3",

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

1 participant