|
//Install the react-native-fs library by running the following command in your project's root directory |
|
npm install react-native-fs --save |
|
|
|
react-native link react-native-fs |
|
import RNFS from 'react-native-fs'; |
|
|
|
// Function to download the Video From Cloud or Storage |
|
async function downloadVideo(videoUrl, savePath) { |
|
try { |
|
const response = await RNFS.downloadFile({ |
|
fromUrl: videoUrl, |
|
toFile: savePath, |
|
}); |
|
|
|
if (response.statusCode === 200) { |
|
console.log('Video downloaded successfully'); |
|
} else { |
|
console.error('Failed to download video:', response.statusCode); |
|
} |
|
} catch (error) { |
|
console.error('Error downloading video:', error); |
|
} |
|
} |
|
|
|
//Call the downloadVideo function |
|
|
|
const videoUrl = 'https://sirangle.com/video.mp4'; // Replace with the actual video URL u are working with |
|
const savePath = `${RNFS.DocumentDirectoryPath}/video.mp4`; // Replace with the desired save path dat u created |
|
downloadVideo(videoUrl, savePath); |
|
|
|
|
|
|
|
// Function to Hide the downloaded Video |
|
|
|
async function hideVideo(videoUrl) { |
|
try { |
|
const hiddenDirPath = `${RNFS.DocumentDirectoryPath}/.hiddenVideos`; |
|
|
|
// Check if the hidden directory exists, if not, create it |
|
const hiddenDirExists = await RNFS.exists(hiddenDirPath); |
|
if (!hiddenDirExists) { |
|
await RNFS.mkdir(hiddenDirPath); |
|
} |
|
|
|
// Extract the video file name from the URL |
|
const videoFileName = videoUrl.split('/').pop(); |
|
|
|
// Set the save path in the hidden directory |
|
const savePath = `${hiddenDirPath}/${videoFileName}`; |
|
|
|
// Download the video file |
|
const response = await RNFS.downloadFile({ |
|
fromUrl: videoUrl, |
|
toFile: savePath, |
|
}); |
|
|
|
if (response.statusCode === 200) { |
|
console.log('Video downloaded and hidden successfully'); |
|
} else { |
|
console.error('Failed to download video:', response.statusCode); |
|
} |
|
} catch (error) { |
|
console.error('Error downloading video:', error); |
|
} |
|
} |
|
|
|
//Call the hideVideo |
|
|
|
const videoUrl = 'https://sirangle.com/video.mp4'; // Replace with the actual video URL u are working with |
|
hideVideo(videoUrl); |
|
|
|
|
|
|
Thanks. But please don't delete the link