Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getPassportUrl(){
console.log('Entered Passport Call');
var storageRef = storage().ref();
var starsRef = storageRef.child('passport/'+ this.userId);
// Get the download URL
starsRef.getDownloadURL().then((result) => {
console.log("Passport",result);
this.passport_url = result;
}).catch(function(error) {
// Handle any errors
});
}
uploadFile(upload: Upload, callback) {
//firebase.initializeApp(environment.firebase,'Cognitivity1');
const storageRef = firebase.storage().ref();
const uploadTask = storageRef.child(`${this.basePath}/${upload.file.name}`)
.put(upload.file);
uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
// three observers
// 1.) state_changed observer
(snapshot) => {
// upload in progress
upload.progress = (uploadTask.snapshot.bytesTransferred / uploadTask.snapshot.totalBytes) * 100;
},
// 2.) error observer
(error) => {
// upload failed
console.log(error);
},
// 3.) success observer
function firebaseUpload(file, logoType, user, onSuccessCallback) {
const storagePath = `${user.id}/images/${logoType}.jpg`;
firebase
.storage()
.ref(storagePath)
.put(file)
.then(snapshot => {
console.log("image upload success");
return snapshot.ref.getDownloadURL();
})
.then(downloadURL => {
// you can assign keys for square logo and horizontal logo with downloadURL value here
// or just provide a callback
onSuccessCallback(downloadURL);
// when 'save settings' is pressed line 314 uploads the key and value (imageurl)
})
.catch(error => {
console.error(error);
alert(error.message);
fileUploadHandler = (file) => {
var user = firebase.auth().currentUser;
var userName = user.displayName
var storageRef = firebase.storage().ref(userName + '/profilePicture/' + file)
var uploadTask = storageRef.put(file)
uploadTask.on('state_changed', function(snapshot){
switch (snapshot.state) {
case firebase.storage.TaskState.PAUSED: // or 'paused'
break;
case firebase.storage.TaskState.RUNNING: // or 'running'
break;
default: console.log('.')
}
}, function(error) {
message.error('Upload error: ', error)
}, function() {
// Handle successful uploads on complete
uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
user.updateProfile({
photoURL: downloadURL
authDomain: process.env.AUTH_DOMAIN,
databaseURL: process.env.DATABASE_URL,
projectId: process.env.PROJECT_ID,
storageBucket: process.env.STORAGE_BUCKET,
messagingSenderId: process.env.MESSAGING_SENDER_ID
}
firebase.initializeApp(config)
} catch (error) {
console.log('=========Firebase initializer==============')
console.log(error)
console.log('====================================')
}
// - Storage reference
export let storageRef = firebase.storage().ref()
// - Database authorize
export let firebaseAuth = firebase.auth
export let firebaseRef = firebase.database().ref()
// - Firebase default
export default firebase
const uploadImage = (uri, mime = 'application/octet-stream') => {
const storage = firebase.storage(); //declare storage here just for this instance
return new Promise((resolve, reject) => {
const uploadUri = Platform.OS === 'ios' ? uri.replace('file://', '') : uri
const sessionId = new Date().getTime()
let uploadBlob = null
const imageRef = storage.ref('images').child(`${sessionId}`)
fs.readFile(uploadUri, 'base64')
.then((data) => {
return Blob.build(data, { type: `${mime};BASE64` })
})
.then((blob) => {
uploadBlob = blob
return imageRef.put(blob, { contentType: mime })
})
.then(() => {
uploadBlob.close()
marginTop: -16
},
menuIcon: {
color: '#fff',
fontSize: 40
},
button: {
backgroundColor: 'rgb(37, 76, 71)',
color: '#fff',
float: 'right'
}
};
return (
<div>
<div>
<ul id="slide-out">
<div style="{style.side}">
<div style="{style.row}">
<span>
<h4>
<i>library_books</i>
Admin
</h4>
</span>
<li>
<p></p></li></div></div></ul></div></div>
private deleteFileStorage(name: string) {
const storageRef = firebase.storage().ref();
storageRef.child(`${this.basePath}/${name}`).delete()
}
}
return new Promise(async (res, rej) => {
const response = await fetch(uri);
const blob = await response.blob();
const ref = firebase.storage().ref(uploadUri);
const unsubscribe = ref.put(blob).on(
'state_changed',
state => {},
err => {
unsubscribe();
rej(err);
},
async () => {
unsubscribe();
const url = await ref.getDownloadURL();
res(url);
},
);
});
}
constructor() {
this.myPhotosRef = firebase.storage().ref("Images/");
}