Upload multiple images on Firebase Storage and then create post
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a file input from which I add a series of images to an array called var immaginiPost =
. I then want to get all of these images and add them to Firebase Storage and then once these are uploaded get also the title and content of a post from other two text inputs and create a post on Firebase Database where I also uplaod every downloadUrl for each image. I have a problem where I need to wait that all images have been uploaded to Storage and all downlaodUrls have been added to the var immaginiDownloadURL =
array before creating the post and I can't figure this out. Thank you in advance.
//Here create a new post
function newPost() {
var postsStorageRef = firebase.storage().ref().child('posts');
var postDatabaseRef = firebase.database().ref().child('posts');
var postKey = firebase.database().ref().child('posts').push().key;
immaginiPost.forEach(function(file){
let uploadTask = postsStorageRef.child(postKey).child(file.name).put(file);
uploadTask.on('state_changed', function(snapshot){
// Observe state change events such as progress, pause, and resume
// 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');
switch (snapshot.state) {
case firebase.storage.TaskState.PAUSED: // or 'paused'
console.log('Upload is paused');
break;
case firebase.storage.TaskState.RUNNING: // or 'running'
console.log('Upload is running');
break;
}
}, function(error) {
// Handle unsuccessful uploads
console.log('Unsuccessful upload');
}, function() {
// Handle successful uploads on complete
// For instance, get the download URL: https://firebasestorage.googleapis.com/...
uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
console.log('File available at', downloadURL);
immaginiDownloadUrl.push(downloadURL);
//Then create the post...
//TODO: Think of how to add all the pictures and then at the end create the post
});
});
});
};
javascript html html5 firebase firebase-storage
add a comment |
I have a file input from which I add a series of images to an array called var immaginiPost =
. I then want to get all of these images and add them to Firebase Storage and then once these are uploaded get also the title and content of a post from other two text inputs and create a post on Firebase Database where I also uplaod every downloadUrl for each image. I have a problem where I need to wait that all images have been uploaded to Storage and all downlaodUrls have been added to the var immaginiDownloadURL =
array before creating the post and I can't figure this out. Thank you in advance.
//Here create a new post
function newPost() {
var postsStorageRef = firebase.storage().ref().child('posts');
var postDatabaseRef = firebase.database().ref().child('posts');
var postKey = firebase.database().ref().child('posts').push().key;
immaginiPost.forEach(function(file){
let uploadTask = postsStorageRef.child(postKey).child(file.name).put(file);
uploadTask.on('state_changed', function(snapshot){
// Observe state change events such as progress, pause, and resume
// 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');
switch (snapshot.state) {
case firebase.storage.TaskState.PAUSED: // or 'paused'
console.log('Upload is paused');
break;
case firebase.storage.TaskState.RUNNING: // or 'running'
console.log('Upload is running');
break;
}
}, function(error) {
// Handle unsuccessful uploads
console.log('Unsuccessful upload');
}, function() {
// Handle successful uploads on complete
// For instance, get the download URL: https://firebasestorage.googleapis.com/...
uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
console.log('File available at', downloadURL);
immaginiDownloadUrl.push(downloadURL);
//Then create the post...
//TODO: Think of how to add all the pictures and then at the end create the post
});
});
});
};
javascript html html5 firebase firebase-storage
add a comment |
I have a file input from which I add a series of images to an array called var immaginiPost =
. I then want to get all of these images and add them to Firebase Storage and then once these are uploaded get also the title and content of a post from other two text inputs and create a post on Firebase Database where I also uplaod every downloadUrl for each image. I have a problem where I need to wait that all images have been uploaded to Storage and all downlaodUrls have been added to the var immaginiDownloadURL =
array before creating the post and I can't figure this out. Thank you in advance.
//Here create a new post
function newPost() {
var postsStorageRef = firebase.storage().ref().child('posts');
var postDatabaseRef = firebase.database().ref().child('posts');
var postKey = firebase.database().ref().child('posts').push().key;
immaginiPost.forEach(function(file){
let uploadTask = postsStorageRef.child(postKey).child(file.name).put(file);
uploadTask.on('state_changed', function(snapshot){
// Observe state change events such as progress, pause, and resume
// 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');
switch (snapshot.state) {
case firebase.storage.TaskState.PAUSED: // or 'paused'
console.log('Upload is paused');
break;
case firebase.storage.TaskState.RUNNING: // or 'running'
console.log('Upload is running');
break;
}
}, function(error) {
// Handle unsuccessful uploads
console.log('Unsuccessful upload');
}, function() {
// Handle successful uploads on complete
// For instance, get the download URL: https://firebasestorage.googleapis.com/...
uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
console.log('File available at', downloadURL);
immaginiDownloadUrl.push(downloadURL);
//Then create the post...
//TODO: Think of how to add all the pictures and then at the end create the post
});
});
});
};
javascript html html5 firebase firebase-storage
I have a file input from which I add a series of images to an array called var immaginiPost =
. I then want to get all of these images and add them to Firebase Storage and then once these are uploaded get also the title and content of a post from other two text inputs and create a post on Firebase Database where I also uplaod every downloadUrl for each image. I have a problem where I need to wait that all images have been uploaded to Storage and all downlaodUrls have been added to the var immaginiDownloadURL =
array before creating the post and I can't figure this out. Thank you in advance.
//Here create a new post
function newPost() {
var postsStorageRef = firebase.storage().ref().child('posts');
var postDatabaseRef = firebase.database().ref().child('posts');
var postKey = firebase.database().ref().child('posts').push().key;
immaginiPost.forEach(function(file){
let uploadTask = postsStorageRef.child(postKey).child(file.name).put(file);
uploadTask.on('state_changed', function(snapshot){
// Observe state change events such as progress, pause, and resume
// 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');
switch (snapshot.state) {
case firebase.storage.TaskState.PAUSED: // or 'paused'
console.log('Upload is paused');
break;
case firebase.storage.TaskState.RUNNING: // or 'running'
console.log('Upload is running');
break;
}
}, function(error) {
// Handle unsuccessful uploads
console.log('Unsuccessful upload');
}, function() {
// Handle successful uploads on complete
// For instance, get the download URL: https://firebasestorage.googleapis.com/...
uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
console.log('File available at', downloadURL);
immaginiDownloadUrl.push(downloadURL);
//Then create the post...
//TODO: Think of how to add all the pictures and then at the end create the post
});
});
});
};
javascript html html5 firebase firebase-storage
javascript html html5 firebase firebase-storage
edited Nov 12 '18 at 11:50
KENdi
5,8792922
5,8792922
asked Nov 11 '18 at 20:56
Alessandro ThegregAlessandro Thegreg
247
247
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253149%2fupload-multiple-images-on-firebase-storage-and-then-create-post%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253149%2fupload-multiple-images-on-firebase-storage-and-then-create-post%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown