I have implemented a way to download file from firebase storage and then saving it into the device. Below is the code that gets the file url and then runs the download request
const extension = type.split('/')[1];
const savedToPath = `${DocumentDirectoryPath}/${filename}.${extension}`;
const headers: Headers = {
Accept: type,
'Content-Type': type,
};
const options: DownloadFileOptions = {
fromUrl: url,
toFile: savedToPath,
headers,
connectionTimeout: 10 * 60 * 1000,
readTimeout: 10 * 60 * 1000,
progressDivider: 10,
progressInterval: 100,
progress: res => this.showProgress(title, res),
};
const response = await downloadFile(options);
const path = await response.promise.then(async res => {
const { statusCode, bytesWritten, jobId } = res;
if (res && res.statusCode === 200 && res.bytesWritten) {
return savedToPath;
}
throw new Error(
`File caching incomplete. Bytes written : ${bytesWritten} Response Code : ${statusCode} JobId : ${jobId}`,
);
});
now the url is a download link for the firebase storage file. for example https://firebasestorage.googleapis.com/v0/b/pangaea-2f1a0.appspot.com/o/media%2F1707074809001_here_gif?alt=media&token=083bd1e8-fa0d-4e82-bb9a-e8a18e412522
I even set the rules in the firebase storage to allow reading from the bucket.
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read;
allow write: if false; // Or any other conditions for write operations
}
}
}
But after doing all of these i end up with a status code of 403 even when i have implemented the rules above. What could possibly be the error.
Below is my error
Fail caching failed: Bytes written: 0 Response Code: 403 JobId: 3
I tried making the firebase storage rules public for both read and write. But i still get the same error