-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: script to upload file to web3 storage and derive storage params
- Loading branch information
Showing
8 changed files
with
30,020 additions
and
1,983 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ yarn-error.log* | |
|
||
# typescript | ||
*.tsbuildinfo | ||
|
||
uploads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { packToFs } from "ipfs-car/pack/fs"; | ||
import { Web3Storage, getFilesFromPath } from "web3.storage"; | ||
|
||
const FILE_PATH = "./path/to/your/file.txt"; | ||
const API_TOKEN = process.env.WEB3_STORAGE_API_TOKEN; | ||
|
||
async function prepFileForStorageDeal() { | ||
try { | ||
// Step 1: Generate the .car file | ||
const carFilePath = "./file.car"; | ||
await packToFs({ | ||
input: FILE_PATH, | ||
output: carFilePath, | ||
}); | ||
|
||
console.log(`.car file created at ${carFilePath}`); | ||
|
||
// Step 2: Upload to IPFS using Web3.Storage | ||
const storage = new Web3Storage({ token: API_TOKEN }); | ||
const files = await getFilesFromPath(carFilePath); | ||
const cid = await storage.put(files); | ||
|
||
console.log("Upload complete"); | ||
console.log("CID:", cid); | ||
console.log("IPFS Gateway URL:", `https://w3s.link/ipfs/${cid}`); | ||
|
||
return { | ||
cid, | ||
carFilePath, | ||
ipfsUrl: `https://w3s.link/ipfs/${cid}`, | ||
}; | ||
} catch (error) { | ||
console.error("Error uploading to IPFS:", error); | ||
} | ||
} | ||
|
||
// Execute the upload function | ||
prepFileForStorageDeal(); |
Oops, something went wrong.