# Curl for object upload

Upload is a multipart request towards Open Content **/opencontent/objectupload** endpoint.

## Curl

Below is how a curl request for upload can look like:&#x20;

```
/usr/bin/curl \
http://<server>:8080/opencontent/objectupload \
-u admin:admin \
-F id=<uuid> \
-F batch=<boolean> \
-F file=<file> \
-F file-mimetype=<mimetype> \ 
-F <file>=@<file> \
-F metadata=<metadata> \
-F metadata-mimetype=npexchange/article \
-F <metadata>=@<metadata> \
-F metadata2=<metadata2> \
-F metadata2-mimetype=npexchange/article \
-F <metadata2>=@<metadata2> \
-F preview=<preview>.jpg \
-F preview-mimetype=image/jpg \ 
-F <preview>.jpg=@<preview>.jpg \
-F thumb=<thumb>.jpg \
-F thumb-mimetype=image/jpg \ 
-F <thumb>.jpg=@<thumb>.jpg \
-F source=<source>
```

| Field                                     |   M/O  | Description                                                                                                                                                                       |
| ----------------------------------------- | :----: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| -F id=\<uuid>                             |    O   | The desired Uiid for the uploaded content object. Open Content will return the given id for the uploaded content.                                                                 |
| -F batch=\<boolean>                       |    O   | Default = false, used to upload content that should be indexed later using the batch indexing mechanism.                                                                          |
| -F file=\<file>                           |    M   | The File Name of the uploaded content.                                                                                                                                            |
| -F file-mimetype=\<mimetype>              |    M   | Mime type for the uploaded content.                                                                                                                                               |
| -F \<file>=@\<file>                       |    M   | \<file> is the same as the given file=\<file>, the file itself                                                                                                                    |
| -F metadata=\<metadata>                   |    M   | Meta Data file                                                                                                                                                                    |
| -F metadata-mimetype=\<metadata-mimetype> |    M   | Meta Data Mime type                                                                                                                                                               |
| -F \<metadata>=@\<metadata>               |    M   | The Meta Data file                                                                                                                                                                |
| -F metadata2=\<metadata2>                 |    O   | If multiple meta data files should be uploaded, use this syntax with index starting at 2.                                                                                         |
| -F metadata2-mimetype2=npexchange/article |    O   |                                                                                                                                                                                   |
| -F \<metadata2>=@\<metadata2>             |    O   |                                                                                                                                                                                   |
| -F preview=\<preview>.jpg                 |        | File name for preview image                                                                                                                                                       |
| -F preview-mimetype=\<mimetype>           |        | Mime type for the preview image                                                                                                                                                   |
| -F \<preview>.jpg=@\<preview>.jpg         |        | The Preview image                                                                                                                                                                 |
| -F thumb=.jpg                             |        | File Name for the image thumbnail                                                                                                                                                 |
| -F thumb-mimetype=\<mime.type>            |        | Mime type for the image thumbnail                                                                                                                                                 |
| -F \<thumb>.jpg=@\<thumb>.jpg             |        | The image thumbnail                                                                                                                                                               |
| -F source=\<source>                       |        | Set the property source to the given value. Please note that the value of this property not can be re-created during a re-index process.                                          |
| *-F reuseFiles=\<boolean>*                | *(\*)* | *If true, the object will get its files from one of the registered storages. Any files in the HTTP request will be ignored. This is used in eventlog replication for example.*    |
| *-F version=\<version>*                   | *(\*)* | *The version of the of the object where files should be reused*                                                                                                                   |
| *-F created=\<created-date>*              | *(\*)* | *The created date of the of the object where files should be reused, format: YYYY-MM-ddTHH:mm:ssZ, example: 2017-05-15T04:41:45Z*                                                 |
| *-F updated=\<updated-date>*              | *(\*)* | *The updated date of the of the object where files should be reused, format: YYYY-MM-ddTHH:mm:ssZ, example: 2017-05-15T04:41:45Z*                                                 |
| *-F eventtype=\<eventtype>*               | *(\*)* | *Possible values: ADD UPDATE DELETE*                                                                                                                                              |
| -H "If-Match:\<hexdecimal etag>"          |        | Enables optimistic locking. This upload will fail if the current object checksum does not match this e-tag. After upload the new e-tag will be returned in response header "ETag" |

{% hint style="info" %}
&#x20;(\*) Is used by the Open Content Replicator when performing replications towards a read only Open Content server
{% endhint %}

| Http statuscode | Description                                                                                      |
| --------------- | ------------------------------------------------------------------------------------------------ |
| 200             | Upload was successful and the object has been updated. The HTTP response body contains the uuid. |
| 201             | Upload was successful and an object has been created. The HTTP response body contains the uuid.  |
| 400             | Upload failed because of an invalid request. The HTTP response body contains the error message.  |
| 401             | Authentication is missing or is incorrect                                                        |
| 409             | Upload failed because it is part of batch indexing.                                              |
| 412             | Upload failed because the E-Tag doesn't match the checksum of the object.                        |
| 500             | Internal server error, unexpected error. The HTTP response body contains the error message.      |
