Open topic with navigation

# Add an Object to a Database (Using a Single Action)

You can train Media Server to recognize an object by sending a single action (`TrainObject`).

Running this action is equivalent to running the following actions in the following order:

- `NewObject`
- `AddObjectImages`
- `SetObjectTrainingOption` (optional)
- `AddObjectMetadata` (optional)
- `BuildObject`

The `TrainObject` action is atomic, so that any interruption to the server does not leave the database in an inconsistent state.

Alternatively, you can train Media Server by sending these actions individually. You might want to do this if you are building a front end application that trains Media Server in response to user input. For more information about how to do this, see Add an Object to a Database (Using Separate Steps).

To add an object to a database (using a single action)

- Add an object using the `TrainObject` action. Set the following parameters:

  `database` | The name of the database to add the object to. The database must already exist.
  `identifier` | (Optional) A unique identifier for the object (maximum 254 bytes). If you do not set this parameter, Media Server generates an identifier automatically.
  `imagedata` | (Set this or `imagepath`, but not both). The training images to add. Files must be uploaded as multipart/form-data. For more information about sending data to Media Server, see Send Data by Using a POST Method.
  `imagepath` | (Set this or `imagedata`, but not both). The paths of the training images to add. The paths must be absolute or relative to the Media Server executable file.
  `imagelabels` | (Optional) A comma-separated list of labels. One label is associated with each image. (maximum 254 bytes for each label). The number of labels must match the number of images. If you do not set this parameter, Media Server generates labels automatically.
  `metadata` | (Optional) A comma-separated list of metadata key-value pairs to add to the object. Separate keys from values using a colon (:). To include a comma or colon in a key name or value, you must enclose the key name or value in quotation marks (`"`) and escape any quotation marks that occur within the string with a backslash (`\`).
  `trainingoptions` | (Optional) A comma-separated list of training options to apply to the object. Separate training options from their values using a colon (:).

  For example:

      curl http://localhost:14000 -F action=TrainObject
                                  -F database=CompanyLogos
                                  -F imagedata=@logo.png
                                  -F "metadata=CompanyName:HPE,\"another:value\":\"1,000\""
                                  -F trainingoptions=useColor:true,3D:false

  Alternatively, the following example provides the path of the training image rather than sending the image data:

      curl http://localhost:14000 -F action=TrainObject
                                  -F database=CompanyLogos
                                  -F imagepath=logo.png
                                  -F "metadata=CompanyName:HPE,\"another:value\":\"1,000\""
                                  -F trainingoptions=useColor:true,3D:false

  Media Server adds the object to the database and returns the identifier.

© 2018 Micro Focus or one of its affiliates | Send documentation feedback to Micro Focus Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a web mail client, and send this email to swpdl.idoldocsfeedback@microfocus.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_FT_HTML5_bannerTitle.htm