Using the WEB version of the SDK to store an image to Firebase Storage. File DOES get uploaded but keep getting the following message when trying to get the download URL
code:"storage/object-not-found"
message:"Firebase Storage: Object 'rainbow_photos/daniel.jpg' does not exist."
name:"FirebaseError"
serverResponse:"{↵ "error": {↵ "code": 404,↵ "message": "Not Found. Could not get object"↵ }↵}"
But the file daniel.jpg DOES get stored in the rainbow_photos folder.
Here's how we are putting the file:
rainbowPhotoUploader.addEventListener('change', function(e){
//Get file
var file = e.target.files[0];
//Create a storage ref
var storageRef = firebase.storage().ref('rainbow_photos/' + file.name);
//Upload file
storageRef.put(file);
//Get URL and store to pass
storageRef.getDownloadURL().then(function(result){
$('#rainbowPhotoURL').val(result);
});
});
There are two ways to download files with Firebase Storage, using references in the SDK or a download URL. iOS and Android users can download files into memory, disk, or from a download URL. The web SDK can download files just from a download URL. StorageReference storageRef = FirebaseStorage.
Once you have a reference, you can download files from Cloud Storage by calling the getBytes() or getStream() . If you prefer to download the file with another library, you can get a download URL with getDownloadUrl() .
Connect to Firebase gradle file, you can use the Tools menu and select Firebase. This will pop out the Firebase Assistant with a list of menu choices. Scroll down to Storage and add Firebase to your project. Choose an existing project or create a new one then add Firebase Storage dependency.
Use "then" for the second time will fire after the file was successfully uploaded. Sorry for my bad English. https://firebase.google.com/docs/storage/web/upload-files
rainbowPhotoUploader.addEventListener('change', function(e) {
var file = e.target.files[0];
var storageRef = firebase.storage().ref('rainbow_photos/' + file.name);
storageRef.put(file).then(function(snapshot) {
// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log('Upload is ' + progress + '% done');
}).then(function() {
// Upload completed successfully, now we can get the download URL
storageRef.getDownloadURL().then(function(downloadURL) {
console.log('File available at', downloadURL);
});
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With