Skip to content

Video file Saving in Ios not working #881

Open
@hussnainshafiul

Description

@hussnainshafiul

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",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions