From ba3704dcce86075b74c84e1d074090802920b546 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 18 Sep 2019 13:31:34 +0200 Subject: [PATCH] preserve original file names --- .travis.yml | 2 +- .../src/routes/Publish/Files/Ipfs/index.tsx | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index a0e7b0a..895dc4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/client/src/routes/Publish/Files/Ipfs/index.tsx b/client/src/routes/Publish/Files/Ipfs/index.tsx index dbdb837..b1ce485 100644 --- a/client/src/routes/Publish/Files/Ipfs/index.tsx +++ b/client/src/routes/Publish/Files/Ipfs/index.tsx @@ -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)