store file name with ipfs upload
This commit is contained in:
parent
eaa49e8b01
commit
1d6c992e8d
|
@ -162,7 +162,7 @@ const AddFunder = ({ appendFundProfile }) => (
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
value={values.funderDescription || ''}
|
value={values.funderDescription || ''}
|
||||||
/>
|
/>
|
||||||
{status && status.profileImg && <img src={status.profileImg} alt='ipfs' style={{maxWidth: '90%'}} />}
|
{status && status.profileImg && <img src={status.profileImg.img} alt='ipfs' style={{maxWidth: '90%'}} />}
|
||||||
<TextField
|
<TextField
|
||||||
id="commitTime"
|
id="commitTime"
|
||||||
name="commitTime"
|
name="commitTime"
|
||||||
|
|
|
@ -10,14 +10,21 @@ export const captureFile = (event, cb, imgCb) => {
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
const file = event.target.files[0]
|
const file = event.target.files[0]
|
||||||
|
console.log({file})
|
||||||
saveToIpfs(file, cb, imgCb)
|
saveToIpfs(file, cb, imgCb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formatForIpfs = file => {
|
||||||
|
const { name, type } = file
|
||||||
|
const content = fileReaderPullStream(file)
|
||||||
|
return [{
|
||||||
|
path: `/root/${name}`,
|
||||||
|
content
|
||||||
|
}]
|
||||||
|
}
|
||||||
const saveToIpfs = (file, cb, imgCb) => {
|
const saveToIpfs = (file, cb, imgCb) => {
|
||||||
let ipfsId
|
let ipfsId
|
||||||
const fileStream = fileReaderPullStream(file)
|
ipfs.add(formatForIpfs(file), { progress: (prog) => console.log(`received: ${prog}`) })
|
||||||
ipfs.add(fileStream, { progress: (prog) => console.log(`received: ${prog}`) })
|
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
ipfsId = response[0].hash
|
ipfsId = response[0].hash
|
||||||
|
@ -30,12 +37,13 @@ const saveToIpfs = (file, cb, imgCb) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getImageFromIpfs = async (hash, cb) => {
|
export const getImageFromIpfs = async (hash, cb) => {
|
||||||
const files = await getFile(hash);
|
const files = await getFile(hash)
|
||||||
const { content } = files[0];
|
const file = files.slice(-1)[0]
|
||||||
const arrayBufferView = new Uint8Array(content);
|
const { content } = file
|
||||||
const blob = new Blob([ arrayBufferView ], { type: "image/jpeg" });
|
const arrayBufferView = new Uint8Array(content)
|
||||||
const img = URL.createObjectURL(blob);
|
const blob = new Blob([ arrayBufferView ], { type: "image/jpeg" })
|
||||||
cb(img)
|
const img = URL.createObjectURL(blob)
|
||||||
|
cb({ ...file, img })
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getFile = CID => {
|
export const getFile = CID => {
|
||||||
|
|
Loading…
Reference in New Issue