Create target via CRS with JS SDK

0 votes
asked Feb 25 by switchtecno (500 points)

Hi, I'm trying to create a new target with a serialized image (base64). But I always get the following error

Error: {
  "result": "Parameter required not exists",
  "statusCode": 4,
  "date": "2019-02-25T21:52:29.352Z",
  "timestamp": 1551131549352
}

Also, I tried to use another feature of the JS SDK, I used count the current (getTargetsCount) targets and works perfectly.

I'm using the base implementation of the SDK from this repo: https://github.com/EasyAR-CRS/nodejs-sdk

Here is my code.

'use strict';

const sdk = require('./farmer');

const fs = require('fs')

var farmer = sdk(

'http://host.com',

'--key--',

'--secret---'

);

var images = fs.readFileSync('./test_search_image.jpg').toString('base64')

farmer.createTarget({

'image': images

})

.then(function(resp) {

console.log(resp.result.targetId);

})

.fail(function(err) {

console.log(err);

});

The image is in the root of the folder. It's a test image included in the repo.

1 Answer

0 votes
answered Feb 25 by switchtecno (500 points)

I found my error. I need to pass all the basic params into the request. I have been passing only image, but the following fields: (image, name, size, meta and type) are required

As the docs says https://www.easyar.com/doc/EasyAR%20CRS/api/target-create.html#

Here is the implementation for future JS references (If someone want need it :) )

const sdk = require('./farmer');

const fs = require('fs')

var farmer = sdk(

'--host--',

'--key--',

'--secret--'

);

var images = fs.readFileSync('./test_search_image.jpg').toString('base64')

farmer.createTarget({

'image': images,

'name': 'test_image_target_bysdk',

'size': '20', // it's important to cast into String, If you don't send it with String type the server don't accept the request

'meta': '',

'type': 'ImageTarget'

})

.then(function(resp) {

console.log(resp.result.targetId);

})

.fail(function(err) {

console.log(err.response.body);

});

Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...