Skip to content

Commit

Permalink
chore: add minimal w3up upload example
Browse files Browse the repository at this point in the history
trying to find a nice minimal example that folks can run and re-run to try thing out.

pulled from storacha/www#22

License: MIT
Signed-off-by: Oli Evans <oli@protocol.ai>
  • Loading branch information
olizilla committed Nov 14, 2023
1 parent aa2ea80 commit b955dba
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
36 changes: 36 additions & 0 deletions packages/w3up-client/example/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as Client from '../src/index.node.js'
import { filesFromPaths } from 'files-from-path'

/**
* Usage:
* node upload.js <email> <space name> <path>
*/
const [,,email, spaceName, path] = process.argv

console.log({email, spaceName, path})

const client = await Client.create()

// first time setup!
if (!client.accounts().length) {
// waits for you to click the link in your email to verify your identity
console.log('💌 Sending a verification link. Plz check your inbox', email)
const account = await client.login(email)

// create a space for your uploads
const space = await client.createSpace(spaceName)

await space.save()

// associate this space with your account
await account.provision(space.did())
}

// content-address your files
const files = await filesFromPaths([path])
console.log('🚀 uploading', path)
const root = await client.uploadDirectory(files)

console.log('root', root.toString())
console.log('space', space.did(), space.name())
console.log('done!')
3 changes: 2 additions & 1 deletion packages/w3up-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
"@web3-storage/upload-client": "workspace:^"
},
"devDependencies": {
"@web3-storage/upload-api": "workspace:^",
"@docusaurus/core": "^2.2.0",
"@ipld/car": "^5.1.1",
"@types/assert": "^1.5.6",
Expand All @@ -116,9 +115,11 @@
"@ucanto/server": "^9.0.1",
"@web3-storage/data-segment": "^5.0.0",
"@web3-storage/eslint-config-w3up": "workspace:^",
"@web3-storage/upload-api": "workspace:^",
"assert": "^2.0.0",
"c8": "^7.13.0",
"docusaurus-plugin-typedoc": "^0.18.0",
"files-from-path": "^1.0.1",
"hundreds": "^0.0.9",
"mocha": "^10.1.0",
"multiformats": "^12.1.2",
Expand Down
12 changes: 11 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b955dba

Please sign in to comment.