1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

preserve original file names

This commit is contained in:
Matthias Kretschmann 2019-09-18 13:31:34 +02:00
parent 6d4b6b77c2
commit ba3704dcce
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 14 additions and 7 deletions

View File

@ -27,7 +27,7 @@ env:
- REACT_APP_FAUCET_URI="http://localhost:3001"
- REACT_APP_BRIZO_ADDRESS="0x068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0"
# start Barge with these versions
- BRIZO_VERSION=v0.4.2
- BRIZO_VERSION=v0.4.4
- AQUARIUS_VERSION=v0.3.8
- KEEPER_VERSION=v0.11.1
- EVENTS_HANDLER_VERSION=v0.1.2

View File

@ -36,16 +36,18 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
)
}, [received])
async function addToIpfs(data: Buffer | ArrayBuffer | File | File[]) {
async function addToIpfs(data: any) {
try {
const response = await ipfs.add(data, {
wrapWithDirectory: true,
progress: (length: number) => {
console.log(`Received: ${formatBytes(length, 0)}`)
setReceived(length)
}
})
console.log(response)
const cid = response[0].hash
// CID of wrapping directory is returned last
const cid = response[response.length - 1].hash
console.log(`File added: ${cid}`)
return cid
} catch (error) {
@ -55,7 +57,7 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
}
async function handleOnDrop(acceptedFiles: File[]) {
const { size } = acceptedFiles[0]
const { name, size } = acceptedFiles[0]
const totalSize = formatBytes(size, 0)
setLoading(true)
@ -64,13 +66,18 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
// Add file to IPFS node
const content: any = await readFileAsync(acceptedFiles[0])
const data = Buffer.from(content)
const cid = await addToIpfs(data)
const fileDetails = {
path: name,
content: data
}
const cid = await addToIpfs(fileDetails)
if (!cid) return
// Ping gateway url to make it globally available,
// but store native url in DDO.
const urlGateway = `${ipfsGatewayUri}/ipfs/${cid}`
const url = `ipfs://${cid}`
const url = `ipfs://${cid}/${name}`
setMessage('Checking IPFS gateway URL')
await pingUrl(urlGateway)