Hi Guys,
I am trying to use saveFile to save a file (uploaded from the react front end) into IPFS.
I am getting the below messages from the console based on my console.log calls, but I can not get the IPFS hash so there must be an issue somewhere.
File {name: "image.png", lastModified: 1627135297645, lastModifiedDate: Sun Jul 25 2021 00:01:37..., webkitRelativePath: "", size: 160822, …}
Promise {<fulfilled>: undefined}
__proto__: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: undefined
Could you please advise what I am doing incorrectly. See below the code of my react component which imports Moralis:
import React, { useState } from 'react'
import './style.css'
import { Button, Form, Modal } from 'react-bootstrap'
import { useMoralis, useMoralisFile } from 'react-moralis'
import { Moralis } from 'moralis'
const UploadDataModal = () => {
const [file, setFile] = useState('')
const [showModal, setShowModal] = useState(false)
const handleClose = () => setShowModal(false)
const handleShow = () => setShowModal(true)
const {saveFile, moralisFile} = useMoralisFile()
const saveFileIPFS = (f) => {
console.log(f)
const fileIpfs = saveFile(f.name, file, {saveIPFS: true})
console.log(fileIpfs)
}
const handleFinal = () => {
saveFileIPFS(file[0])
handleClose()
}
return (
<>
<Button variant="warning" onClick={handleShow}>
Upload File
</Button>
<Modal show={showModal} onHide={handleClose}>
<Modal.Header closeButton>
<Modal.Title>
Upload file
</Modal.Title>
</Modal.Header>
<Modal.Body>
<Form>
<Form.Group className="mb-3" controlId="formBasicEmail">
<Form.Label>Upload the file</Form.Label>
<Form.Control
type="file"
placeholder="Upload the file"
onChange={(e) => setFile(e.target.files)}
/>
</Form.Group>
</Form>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
<Button variant="primary" onClick={handleFinal}>
Add
</Button>
</Modal.Footer>
</Modal>
</>
)
}
export default UploadDataModal