Firebase tips(Storage rule)
9909 단어 Firebase
FIREBASE TIPS
1. Allow user to be able to upload profile.png in own directory.
storage.ruleservice firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read: if request.auth != null;
}
match /images/{userId}/profile.png {
allow read;
allow write: if request.auth.uid == userId;
}
}
}
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read: if request.auth != null;
}
match /images/{userId}/profile.png {
allow read;
allow write: if request.auth.uid == userId;
}
}
}
<script>
firebase.initializeApp(config);
firebase.auth().signInWithEmailAndPassword('[email protected]', 'xxxxx').catch((error) => {
console.log('code:' + error.code + 'message' + error.message);
});
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
let uid = user.uid;
console.log('login success');
} else { }
});
var storage = firebase.storage();
function upload() {
var file = document.getElementById('loadFile').files[0];
var storageRef = storage.ref('/images/eFcFmn2lbqTzXf83vtHPdSCID9W2/profile.png');
storageRef.put(file).then(function (snapshot) {
console.log('Uploaded a blob or file!');
});
}
</script>
result

result

<script>
firebase.initializeApp(config);
firebase.auth().signInWithEmailAndPassword('[email protected]', 'xxxxx').catch((error) => {
console.log('code:' + error.code + 'message' + error.message);
});
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
let uid = user.uid;
console.log('login success');
} else { }
});
var storage = firebase.storage();
function upload() {
var file = document.getElementById('loadFile').files[0];
var storageRef = storage.ref('/images/eFcFmn2lbqTzXf83vtHPdSCID9W2/profile.png');
storageRef.put(file).then(function (snapshot) {
console.log('Uploaded a blob or file!');
});
}
</script>
result

Reference
이 문제에 관하여(Firebase tips(Storage rule)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/coffee_and_code/items/2dda4cb4cf30a26cb930텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)