putFile Throws (No object exists at the desired reference) #6604
-
Issue(:fire:) I am trying to upload a PDF file to Storage. The
Here is the code: // To help in troubleshooting the problem, I am hard-coding the path below. On the actual app, the path is received from DocumentPicker.pick() - from react-native-document-picker
// I tried each of the following. None of them worked!
const pathToFile = "file:///storage/emulated/0/Android/data/com.casualjob/files/Download/sample.pdf";
// const pathToFile = "file:/storage/emulated/0/Android/data/com.casualjob/files/Download/sample.pdf";
// const pathToFile = "/storage/emulated/0/Android/data/com.casualjob/files/Download/sample.pdf";
<Button title={"Testing Code"}
onPress={async () => {
// To double-check that the file exists:
const exist = await RNFetchBlob.fs.exists(pathToFile);
console.log("_saveFiles - RNFetchBlob.fs.exists - ", pathToFile, `${exist ? " exists" : " does NOT exist"}`); // result: file exists!
const reference = storage().ref("sample.pdf");
const task = await reference.putFile(pathToFile); // Code fails here with the error (above)
task.on("state_changed", taskSnapshot => {
console.log(`${taskSnapshot.bytesTransferred} transferred out of ${taskSnapshot.totalBytes}`);
});
task.then(() => {
console.log("Image uploaded to the bucket!");
});
}}
/>
<Pdf // The PDF file is displayed correctly on the screen (using the same path, which putFile does NOT like above!
source={{uri: pathToFile}}
style={{ width: 100, height: 80, }}
/> Project FilesJavascriptClick To Expand
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Possibly restricted by storage access rules. |
Beta Was this translation helpful? Give feedback.
-
@mikehardy I am really grateful to you! The error message sounded to me like a problem with accessing the file on the device (and not the cloud)! However, you are right, as always! I visited the project's page on the console to check the Cloud Storage access rules. I was surprised to see a 'Get started" button! For a few months, I have been uploading and accessing files and being charged (a few cents) for it! This code has been working for a few months (in a dev environment)! Well, life is better because of people like you!!! Thank you so much... |
Beta Was this translation helpful? Give feedback.
-
My this issue: is resolved by adding the latest: |
Beta Was this translation helpful? Give feedback.
Possibly restricted by storage access rules.