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:
parent
6d4b6b77c2
commit
ba3704dcce
@ -27,7 +27,7 @@ env:
|
|||||||
- REACT_APP_FAUCET_URI="http://localhost:3001"
|
- REACT_APP_FAUCET_URI="http://localhost:3001"
|
||||||
- REACT_APP_BRIZO_ADDRESS="0x068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0"
|
- REACT_APP_BRIZO_ADDRESS="0x068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0"
|
||||||
# start Barge with these versions
|
# start Barge with these versions
|
||||||
- BRIZO_VERSION=v0.4.2
|
- BRIZO_VERSION=v0.4.4
|
||||||
- AQUARIUS_VERSION=v0.3.8
|
- AQUARIUS_VERSION=v0.3.8
|
||||||
- KEEPER_VERSION=v0.11.1
|
- KEEPER_VERSION=v0.11.1
|
||||||
- EVENTS_HANDLER_VERSION=v0.1.2
|
- EVENTS_HANDLER_VERSION=v0.1.2
|
||||||
|
@ -36,16 +36,18 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
|||||||
)
|
)
|
||||||
}, [received])
|
}, [received])
|
||||||
|
|
||||||
async function addToIpfs(data: Buffer | ArrayBuffer | File | File[]) {
|
async function addToIpfs(data: any) {
|
||||||
try {
|
try {
|
||||||
const response = await ipfs.add(data, {
|
const response = await ipfs.add(data, {
|
||||||
|
wrapWithDirectory: true,
|
||||||
progress: (length: number) => {
|
progress: (length: number) => {
|
||||||
console.log(`Received: ${formatBytes(length, 0)}`)
|
console.log(`Received: ${formatBytes(length, 0)}`)
|
||||||
setReceived(length)
|
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}`)
|
console.log(`File added: ${cid}`)
|
||||||
return cid
|
return cid
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -55,7 +57,7 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleOnDrop(acceptedFiles: File[]) {
|
async function handleOnDrop(acceptedFiles: File[]) {
|
||||||
const { size } = acceptedFiles[0]
|
const { name, size } = acceptedFiles[0]
|
||||||
const totalSize = formatBytes(size, 0)
|
const totalSize = formatBytes(size, 0)
|
||||||
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
@ -64,13 +66,18 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
|||||||
// Add file to IPFS node
|
// Add file to IPFS node
|
||||||
const content: any = await readFileAsync(acceptedFiles[0])
|
const content: any = await readFileAsync(acceptedFiles[0])
|
||||||
const data = Buffer.from(content)
|
const data = Buffer.from(content)
|
||||||
const cid = await addToIpfs(data)
|
const fileDetails = {
|
||||||
|
path: name,
|
||||||
|
content: data
|
||||||
|
}
|
||||||
|
|
||||||
|
const cid = await addToIpfs(fileDetails)
|
||||||
if (!cid) return
|
if (!cid) return
|
||||||
|
|
||||||
// Ping gateway url to make it globally available,
|
// Ping gateway url to make it globally available,
|
||||||
// but store native url in DDO.
|
// but store native url in DDO.
|
||||||
const urlGateway = `${ipfsGatewayUri}/ipfs/${cid}`
|
const urlGateway = `${ipfsGatewayUri}/ipfs/${cid}`
|
||||||
const url = `ipfs://${cid}`
|
const url = `ipfs://${cid}/${name}`
|
||||||
|
|
||||||
setMessage('Checking IPFS gateway URL')
|
setMessage('Checking IPFS gateway URL')
|
||||||
await pingUrl(urlGateway)
|
await pingUrl(urlGateway)
|
||||||
|
Loading…
Reference in New Issue
Block a user