async function saveFileFromBufferToIPFSAndDisk (req, buffer) {
  // make sure user has authenticated before saving file
  if (!req.session.cnodeUserUUID) {
    throw new Error('User must be authenticated to save a file')
  }

  const ipfs = req.app.get('ipfsAPI')

  // Add to IPFS without pinning and retrieve multihash
  const multihash = (await ipfs.add(buffer, { pin: false }))[0].hash

  // Write file to disk by multihash for future retrieval
  const dstPath = DiskManager.computeFilePath(multihash)
  await fs.writeFile(dstPath, buffer)

  return { multihash, dstPath }
}
/**
 * Adds file to IPFS then saves file to disk under /multihash name
 */
Adds file to IPFS then saves file to disk under /multihash name
Adds file to IPFS then saves file to disk under / multihash name
async function saveFileFromBufferToIPFSAndDisk (req, buffer) {
  if (!req.session.cnodeUserUUID) {
    throw new Error('User must be authenticated to save a file')
  }
  const ipfs = req.app.get('ipfsAPI')
  const multihash = (await ipfs.add(buffer, { pin: false }))[0].hash
  const dstPath = DiskManager.computeFilePath(multihash)
  await fs.writeFile(dstPath, buffer)
  return { multihash, dstPath }
}
async function saveFileFromBufferToIPFSAndDisk ( req , buffer ) { if ( ! req . session . cnodeUserUUID ) { throw new Error ( 'User must be authenticated to save a file' ) } const ipfs = req . app . get ( 'ipfsAPI' ) const multihash = ( await ipfs . add ( buffer , { pin : false } ) ) [ 0 ] . hash const dstPath = DiskManager . computeFilePath ( multihash ) await fs . writeFile ( dstPath , buffer ) return { multihash , dstPath } }
Adds file to IPFS then saves file to disk under /multihash name
Adds file to IPFS then saves file to disk under / multihash name
// make sure user has authenticated before saving file // Add to IPFS without pinning and retrieve multihash // Write file to disk by multihash for future retrieval