web3-storage / web3.storage

DEPRECATED ⁂ The simple file storage service for IPFS & Filecoin
https://web3.storage
Other
502 stars 122 forks source link

getFilesFromPath without root dir #1714

Closed alexbakers closed 2 years ago

alexbakers commented 2 years ago

Hello, friends.

I upload /dir to IPFS, and have URL ipfs://bafy.../dir/index.html

Is it possible not to upload a folder /dir - ipfs://bafy.../index.html?

alexbakers commented 2 years ago

Now I solve it like this.

  const storage = new web3.Web3Storage({ token: process.env.STORAGE });
  const files = await web3.getFilesFromPath(path.join(process.cwd(), "dir"));
  const cid = await storage.put(
    files.map((f) => {
      return { ...f, name: f.name.replace("/dir", "") };
    })
  );
dchoi27 commented 2 years ago

You can set the wrapWithDirectory option for put to false