How to upload file to Firebase Storage after submit ? (React class component)
- Dominant language
- TypeScript
- Stars
- 285
- Forks
- 307
- PR merge metrics
- No merged PRs in 30d
Description
Hi everyone. I have a problem with uploading images to the firebase storage after Submission. In the current situation, when I upload images to the Editor.js, images are uploaded to the Firebase Storage immediately! I cannot take the uploaded file and put it into the handleSubmit function and then add to the Firebase Storage. I have a class component and `const EDITOR_JS_TOOLS` is inside the render(). What should I do in this situation and which method I should follow ? Thanks.
My image plugin is like this :
```
async uploadByFile(file) {
var storageRef = firebase.storage().ref();
var imagesRef = storageRef.child('EditorJS').child('images/${file.name}');
var metadata = {
contentType: 'image/jpeg'
};
var uploadTask = await imagesRef.put(file, metadata);
console.log("Uploaded successfully!", uploadTask);
const downloadURL = await uploadTask.ref.getDownloadURL();
console.log(downloadURL);
alert('IMAGE UPLOADED')
return {
success: 1,
file: {
url: downloadURL,
}
}
}
```
And my Submit function is like :
```
handleSubmit = (e) => {
e.preventDefault();
console.log(this.state);
this.props.createProject(this.state);
this.props.history.push('/');
}
```
And also I save Editor.JS data to the state like this :
```
async handleSave() {
const savedData = await this.editorInstance.save();
console.log(savedData);
this.setState({
saved: savedData.blocks,
})
console.log(this.state);
this.setState({
publishModal: true,
})
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.