vincenzoAiello / DArchive

3 stars 4 forks source link

Error when trying to upload a file, #3

Closed alexanderbkl closed 2 years ago

alexanderbkl commented 2 years ago

When I try to upload a file, an errors comes up:

constants.js:2 Uncaught (in promise) TypeError: Invalid attempt to iterate non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.
    at _createForOfIteratorHelperLoose (constants.js:2:1)
    at writeAll$ (index.js:29:1)
    at tryCatch (regeneratorRuntime.js:86:1)
    at Generator._invoke (regeneratorRuntime.js:66:1)
    at Generator.next (regeneratorRuntime.js:117:1)
    at tryCatch (regeneratorRuntime.js:86:1)
    at invoke (regeneratorRuntime.js:124:1)
    at regeneratorRuntime.js:148:1
    at new Promise (<anonymous>)
    at callInvokeWithMethodAndArg (regeneratorRuntime.js:147:1)
    at AsyncIterator._invoke (regeneratorRuntime.js:152:1)
    at AsyncIterator.next (regeneratorRuntime.js:117:1)
    at exports.async (regeneratorRuntime.js:238:1)
    at writeAll (index.js:29:1)
    at Object.<anonymous> (index.js:46:1)
    at Object.asyncIterableReader (decoder.js:228:1)
    at CarReader.fromIterable (reader-browser.js:47:1)
    at put$ (lib.js:97:1)
    at tryCatch (regeneratorRuntime.js:86:1)
    at Generator._invoke (regeneratorRuntime.js:66:1)
    at Generator.next (regeneratorRuntime.js:117:1)
    at tryCatch (regeneratorRuntime.js:86:1)
    at invoke (regeneratorRuntime.js:124:1)
    at regeneratorRuntime.js:130:1

constants.js in ipfs-car module contains this code:

import { sha256 } from 'multiformats/hashes/sha2';
export const unixfsImporterOptionsDefault = {
    cidVersion: 1,
    chunker: 'fixed',
    maxChunkSize: 262144,
    hasher: sha256,
    rawLeaves: true,
    wrapWithDirectory: true,
    maxChildrenPerNode: 174
};

The sha256 method on the code above includes some "crypto" modules. Maybe that's the reason of failure related to some cryptography.

On ipfs-car/dist/esm/pack/index.js line 29, related to constants.js, this piece of code gives error:

   const writeAll = async () => {
        for await (const block of blockstore.blocks()) {
            // `await` will block until all bytes in `carOut` are consumed by the user
            // so we have backpressure here
            await writer.put(block);
        }
        await writer.close();
        if (!userBlockstore) {
            await blockstore.close();
        }
    };

I'm not able to upload a file to IPFS from localhost neither Github Pages. Maybe this bundle can help with debugging: https://alexanderbkl.github.io/DApp-Web3-IPFS-Expo/ . I would appreciate on giving an answer or at least any clues Also if anyone could give me a version of this repository that is already working and configured would be appreciated as I am working to implement blockchain technoplogy instead of Firebase SDK as a way of storing the data in a totally decentralized manner. Thanks in advance!

alexanderbkl commented 2 years ago

Solved by deleting everything and starting from scratch by doing a git clone, npm install and create a config.js firebase file. I've messed with the node_modules, that was the problem.