storacha-network / w3up

⁂ w3up protocol implementation
https://github.com/storacha-network/specs
Other
54 stars 19 forks source link

YOUR SOLUTION IS NOT CORRECT! #1475

Closed playground closed 3 months ago

playground commented 3 months ago

Following instructions https://web3.storage/docs/ to store a file

import * as Client from '@web3-storage/w3up-client'
import { filesFromPaths } from 'files-from-path'

const client = await Client.create()
const files = await filesFromPaths(['/Users/test/w3up/example.json'])
client.uploadFile(files).then((did) => console.log(did))

but getting these errors

learnyouw3up verify ex3.mjs
Verifying /Users/test/w3up/ex3.mjs...

file:///Users/test/.nvm/versions/node/v18.17.1/lib/node_modules/learnyouw3up/node_modules/execa/lib/error.js:60
                error = new Error(message);
                        ^

Error: Command failed with exit code 1: /Users/test/.nvm/versions/node/v18.17.1/bin/node /Users/test/w3up/ex3.mjs
file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/unixfs.js:51
        await this.#file.stream().pipeTo(new WritableStream({
                         ^

TypeError: this[#file].stream is not a function
    at UnixFSFileBuilder.finalize (file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/unixfs.js:51:26)
    at file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/unixfs.js:33:27
    at Module.createFileEncoderStream (file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/unixfs.js:35:7)
    at uploadFile (file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/index.js:38:49)
    at Client.uploadFile (file:///Users/test/w3up/node_modules/@web3-storage/w3up-client/dist/src/client.js:92:16)

Node.js v18.17.1
    at makeError (file:///Users/test/.nvm/versions/node/v18.17.1/lib/node_modules/learnyouw3up/node_modules/execa/lib/error.js:60:11)
    at handlePromise (file:///Users/test/.nvm/versions/node/v18.17.1/lib/node_modules/learnyouw3up/node_modules/execa/index.js:124:26)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///Users/test/.nvm/versions/node/v18.17.1/lib/node_modules/learnyouw3up/problems/2-cat-gifs/index.js:21:29 {
  shortMessage: 'Command failed with exit code 1: /Users/test/.nvm/versions/node/v18.17.1/bin/node /Users/test/w3up/ex3.mjs',
  command: '/Users/test/.nvm/versions/node/v18.17.1/bin/node /Users/test/w3up/ex3.mjs',
  escapedCommand: '"/Users/test/.nvm/versions/node/v18.17.1/bin/node" "/Users/test/w3up/ex3.mjs"',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: 'file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/unixfs.js:51\n' +
    '        await this.#file.stream().pipeTo(new WritableStream({\n' +
    '                         ^\n' +
    '\n' +
    'TypeError: this[#file].stream is not a function\n' +
    '    at UnixFSFileBuilder.finalize (file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/unixfs.js:51:26)\n' +
    '    at file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/unixfs.js:33:27\n' +
    '    at Module.createFileEncoderStream (file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/unixfs.js:35:7)\n' +
    '    at uploadFile (file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/index.js:38:49)\n' +
    '    at Client.uploadFile (file:///Users/test/w3up/node_modules/@web3-storage/w3up-client/dist/src/client.js:92:16)\n' +
    '\n' +
    'Node.js v18.17.1',
  cwd: '/Users/test/w3up',
  all: 'file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/unixfs.js:51\n' +
    '        await this.#file.stream().pipeTo(new WritableStream({\n' +
    '                         ^\n' +
    '\n' +
    'TypeError: this[#file].stream is not a function\n' +
    '    at UnixFSFileBuilder.finalize (file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/unixfs.js:51:26)\n' +
    '    at file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/unixfs.js:33:27\n' +
    '    at Module.createFileEncoderStream (file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/unixfs.js:35:7)\n' +
    '    at uploadFile (file:///Users/test/w3up/node_modules/@web3-storage/upload-client/dist/src/index.js:38:49)\n' +
    '    at Client.uploadFile (file:///Users/test/w3up/node_modules/@web3-storage/w3up-client/dist/src/client.js:92:16)\n' +
    '\n' +
    'Node.js v18.17.1',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

Node.js v18.17.1
playground commented 3 months ago

#########################################
###   YOUR SOLUTION IS NOT CORRECT!   ###
#########################################

Invalid CID: ""
alanshaw commented 3 months ago

uploadFile expects a single file, not an array. Try using uploadDirectory or files[0] in you call.