I’ve make a folder in my storage named ‘API produk’
I’ve try to add my folder name in my storageBucket URL like this :
And showing error Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at…(Reason: CORS preflight response did not succeed).
What’s the correct storageBucket URL for this case ?
Or is there any other option ?
Here’s my complete code :
const firebaseConfig = {
apiKey: " ",
authDomain: " ",
projectId: " ",
storageBucket: " ",
messagingSenderId: " ",
appId: " ",
measurementId: " "
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
console.log(firebase);
function uploadImage() {
const ref = firebase.storage().ref();
const file = document.querySelector("#foto").files[0];
const name = +new Date() + "-" + file.name;
const metadata = {
contentType: file.type
};
const task = ref.child(name).put(file, metadata);task
.then(snapshot => snapshot.ref.getDownloadURL())
.then(url => {
console.log(url);
alert('SUKSES !');
urlFoto.value=url;
})
.catch(console.error);
}