Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

object.put: Stored object was different from constructed object #370

Closed
nycoliver opened this issue Sep 6, 2016 · 6 comments
Closed

object.put: Stored object was different from constructed object #370

nycoliver opened this issue Sep 6, 2016 · 6 comments

Comments

@nycoliver
Copy link

Following code throws error: stored object was different from constructed object

Tested on os x 10.11 and ipfs v4.0.2 and latest master 0.4.4-dev. Also tested on a fresh debian digitalocean box. Tested with multiple files.

var ipfs = require('ipfs-api')();
var fs = require('fs');

fs.readFile('./test.jpg', (err, file) => {
  ipfs.object.put(file, (err, object) => {
    console.log(err, object)
  })
})
Error: Stored object was different from constructed object
    at ./node_modules/ipfs-api/lib/api/object.js:110:27
    at finish (./node_modules/wreck/lib/index.js:360:16)
    at wrapped (./node_modules/hoek/lib/index.js:871:20)
    at onReaderFinish (./node_modules/wreck/lib/index.js:406:16)
    at g (events.js:286:16)
    at emitNone (events.js:91:20)
    at emit (events.js:185:7)
    at finishMaybe (_stream_writable.js:488:14)
    at endWritable (_stream_writable.js:498:3)
    at Writable.end (_stream_writable.js:463:5) undefined

I got the hash of result object from https://github.com/ipfs/js-ipfs-api/blob/master/src/api/object.js#L84

ipfs object get that hash throws Error: EOF. So I have a feeling this may be related to #368

@dignifiedquire
Copy link
Contributor

Does this happen with a specific file, or with any files? If so can you provide the file that triggers this?

@dignifiedquire
Copy link
Contributor

Also, object.put is not intended to be used to add raw file content, if you want to add files to ipfs you should use add.

The object api expects you to input valid DAG objects that it can encode. For reference the help output from ipfs object get --help

USAGE
  ipfs object put <data> - Store input as a DAG object, print its key.

SYNOPSIS
  ipfs object put [--inputenc=<inputenc>] [--datafieldenc=<datafieldenc>] [--] <data>

ARGUMENTS

  <data> - Data to be stored as a DAG object.

OPTIONS

  --inputenc     string - Encoding type of input data. One of: {"protobuf", "json"}. Default: json.
  --datafieldenc string - Encoding type of the data field, either "text" or "base64". Default: text.

DESCRIPTION

  'ipfs object put' is a plumbing command for storing DAG nodes.
  It reads from stdin, and the output is a base58 encoded multihash.

  Data should be in the format specified by the --inputenc flag.
  --inputenc may be one of the following:
        * "protobuf"
        * "json" (default)

  Examples:

        $ echo '{ "Data": "abc" }' | ipfs object put

  This creates a node with the data 'abc' and no links. For an object with
  links, create a file named 'node.json' with the contents:

      {
          "Data": "another",
          "Links": [ {
              "Name": "some link",
              "Hash": "QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V",
              "Size": 8
          } ]
      }

  And then run:

        $ ipfs object put node.json

@nycoliver
Copy link
Author

object.put takes either a DAG object or a buffer, which gets treated as the data field. See https://github.com/ipfs/interface-ipfs-core/tree/master/API/object and https://github.com/ipfs/js-ipfs-api/blob/master/src/api/object.js#L57. But yes, I should be using files.add as object size limit is 512kb.

Tested with multiple files / any file triggers this.

@zbyte64
Copy link

zbyte64 commented Oct 11, 2016

My experience has been that if you wrap a Buffer with DAGNode then object.put works. The following is from a code base of mine and works:

    let bufferState = new Buffer(JSON.stringify(state));
    let newDagNode = new DAGNode(bufferState);
    if (currentMultiHash) {
      return ipfs.object.patch.setData(currentMultiHash, bufferState);
    } else {
      return ipfs.object.put(newDagNode);
    }

@daviddias
Copy link
Contributor

@nycoliver is this still a issue? Given the constraints that objects have a limit of 256KiB in size

@daviddias
Copy link
Contributor

Closing, reopen if necessary

@daviddias daviddias removed the ready label Dec 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants