# IRPCObjectOperations.AddObjectFile

Location: [gRPC API](https://developer.m-files.com/APIs/gRPC-API/index.md) > [Vault API](https://developer.m-files.com/APIs/gRPC-API/vault/index.md) > [Objects, versions, properties and files](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/index.md)

HTML version: https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/AddObjectFile/

Badges: `Vault API / core` `write` `session or assertion` `returns metadata structure version`

Adds new document file to a document.

- **Service:** [Objects, versions, properties and files](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/index.md) `MFiles.IRPCObjectOperations`
- **gRPC method:** `/MFiles.IRPCObjectOperations/AddObjectFile`
- **HTTP (mf-http-grpc):** `POST /grpc/v1/add-object-file`
- **Request:** [`AddObjectFileRequest`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/AddObjectFile/index.md#request)
- **Response:** [`AddObjectFileResponse`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/AddObjectFile/index.md#response)
- **Book and level:** Vault API, core
- **Kind:** write
- **Session:** Required: a session (mfiles-session-id-bin metadata) or a session assertion (x-mf-session-assertion metadata).
- **Idempotent:** no
- **Returns metadata structure version:** yes (in the mfiles-metadata-version-bin trailer)
- **Streaming:** none (unary)

<a id="remarks"></a>

## Remarks

Adds a file record to a checked-out object; the content is uploaded separately. On a checked-in
object the call fails with "The object is not checked out." The sequence that works:

1. [CheckOut](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/CheckOut/index.md) the object.
2. AddObjectFile with the checked-out version: returns `file_ver`.
3. [UploadFile](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/UploadFile/index.md) with `upload_id: 0`, the object,
   `file { file_ver, title, extension, size }` and the content, then
   [UploadFileCommit](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/UploadFileCommit/index.md) with the returned
   `upload_id` and the same `file`.
4. [CheckIn](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/CheckIn/index.md).

A file whose content is never committed is dropped at check-in. To create a new document with
files, use
[AddObjectWithFiles](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/AddObjectWithFiles/index.md) instead.

<a id="request"></a>

## Request: AddObjectFileRequest

> Nested message fields are expanded to depth 3; follow a type link for deeper levels and for the type's own page.

| Field | Type | Description |
|---|---|---|
| `obj_ver` | [`ObjVer`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjVer/index.md) | The checked-out version, by number. |
| `obj_ver.obj_id` | [`ObjID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjID/index.md) | The object. |
| `obj_ver.obj_id.type` | `int32` | The object type ID, for example 0 for documents. In a lookup value, the value list ID (for a lookup to objects, the object type ID). |
| `obj_ver.obj_id.item_id` | [`ItemID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ItemID/index.md) | The ID of the object within its type, in `item_id.internal_id`. |
| `obj_ver.version` | [`ObjVerVersion`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjVerVersion/index.md) | The version. Usually `OBJ_VER_VERSION_TYPE_SPECIFIC` with `internal_version`. |
| `obj_ver.version.type` | [`ObjVerVersionType`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.ObjVerVersionType/index.md) | What `internal_version` means. `OBJ_VER_VERSION_TYPE_SPECIFIC` for a version number. Values: `OBJ_VER_VERSION_TYPE_UNINITIALIZED` (0), `OBJ_VER_VERSION_TYPE_LATEST` (1), `OBJ_VER_VERSION_TYPE_ANY` (2), `OBJ_VER_VERSION_TYPE_ALL` (3), `OBJ_VER_VERSION_TYPE_SPECIFIC` (4), `OBJ_VER_VERSION_TYPE_VALUE_LIST_ITEM` (6), `OBJ_VER_VERSION_TYPE_OBJECT_LEVEL_REFERENCE` (7). |
| `obj_ver.version.internal_version` | `int32` | The version number, starting from 1, when `type` is `OBJ_VER_VERSION_TYPE_SPECIFIC`. The server returns -1 with `OBJ_VER_VERSION_TYPE_LATEST`. |
| `obj_ver.version.external_repository_version` | `string` | Used only for objects in external repositories. Leave empty. |
| `obj_ver.version.external_repository_sort_key` | `int64` | Used only for objects in external repositories. Leave 0. |
| `title` | `string` | The file name without the extension. |
| `extension` | `string` | The file extension without the dot, for example `pdf`. |
| `created_at_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | The file's original creation time, if known. Optional. |
| `accessed_at_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | The file's last access time, if known. Optional. |
| `written_at_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | The file's last write time, if known. Optional. |
| `changed_at_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | The file's last change time, if known. Optional. |
| `can_update_object_last_modified_timestamp` | `bool` | True to let the server update the object's Last modified timestamp from this change. |

<a id="response"></a>

## Response: AddObjectFileResponse

> Nested message fields are expanded to depth 3; follow a type link for deeper levels and for the type's own page.

| Field | Type | Description |
|---|---|---|
| `file_ver` | [`FileVer`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.FileVer/index.md) | The new file's ID and version; pass it to UploadFile as `file.file_ver`. |
| `file_ver.file_id` | [`FileID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.FileID/index.md) | The file. |
| `file_ver.file_id.type` | [`FileIDType`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.FileIDType/index.md) | `FILE_IDTYPE_SPECIFIC` for one file. Values: `FILE_IDTYPE_UNINITIALIZED` (0), `FILE_IDTYPE_ALL` (1), `FILE_IDTYPE_ANY` (2), `FILE_IDTYPE_SPECIFIC` (3). |
| `file_ver.file_id.internal_id` | `int32` | The file ID. |
| `file_ver.file_id.external_repository_id` | `string` | Used only for files in external repositories. Leave empty. |
| `file_ver.type` | [`FileVerType`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.FileVerType/index.md) | `FILE_VER_TYPE_SPECIFIC` for a file version number. Values: `FILE_VER_TYPE_UNINITIALIZED` (0), `FILE_VER_TYPE_LATEST` (1), `FILE_VER_TYPE_ANY` (2), `FILE_VER_TYPE_SPECIFIC` (3). |
| `file_ver.internal_version` | `int32` | The file version number. |
| `file_ver.external_repository_version` | `string` | Used only for files in external repositories. Leave empty. |
| `file_ver.external_repository_sort_key` | `int64` | Used only for files in external repositories. Leave 0. |
| `result` | [`ObjectVersionEx`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjectVersionEx/index.md) | The checked-out version after the operation, with its files. |
| `result.version_info` | [`ObjectVersion`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjectVersion/index.md) | Object Version information. |
| `result.version_info.version` | [`ObjVerVersion`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjVerVersion/index.md) | The version number, as a specific version. |
| `result.version_info.display_version` | `string` | The version label to show, if it differs from the version number; empty otherwise. |
| `result.version_info.title` | `string` | The title (name) of the object in this version. |
| `result.version_info.is_single_file_object` | `bool` | True if the object is a single-file document, which has exactly one file. |
| `result.version_info.has_relationships_from_this` | `bool` | Note: this field is deprecated. True if relationships from this object version to one or more documents exist. |
| `result.version_info.has_relationships_to_this` | `bool` | Note: this field is deprecated. True if relationships from one or more documents to this object version exist. |
| `result.version_info.has_assignments` | `bool` | True if relationships from one or more assignments to this object version exist. |
| `result.version_info.last_modified_at_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | When the version was last modified, in UTC. |
| `result.version_info.files[]` | repeated [`File`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.File/index.md) | The files of this version. Each `file_ver` can be passed to `DownloadFile_Begin`. |
| `result.version_info.object_version_flags` | [`OBJVERFLAGS`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.OBJVERFLAGS/index.md) | Bit flags that provide additional information on the object version. |
| `result.version_info.class_id` | `int32` | The class ID of the version. |
| `result.version_info.version_guid` | `string` | The GUID of this version. |
| `result.version_info.base_properties[]` | repeated [`PropertyValue`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.PropertyValue/index.md) | Not filled by the object read methods; read the property values with `GetObjectVersionAndPropertiesOfMultipleObjects` or `GetProperties`. |
| `result.version_info.primary_file` | [`FileID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.FileID/index.md) | File ID of the primary file of a multi-file object, if the object is a multi-file object. |
| `result.object_info` | [`ObjectLevelInfo`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjectLevelInfo/index.md) | Object-level information. |
| `result.object_info.obj_id` | [`ObjID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjID/index.md) | The object type and ID of the object. |
| `result.object_info.external_id_status` | [`ExtIDStatus`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.ExtIDStatus/index.md) | The status of this object's external ID. Values: `EXT_IDSTATUS_UNKNOWN` (0), `EXT_IDSTATUS_EXTERNAL` (1), `EXT_IDSTATUS_INTERNAL` (2), `EXT_IDSTATUS_DISCARDED` (3), `EXT_IDSTATUS_NOT_AVAILABLE` (4), `EXT_IDSTATUS_EXTERNAL_REDUCED` (5). |
| `result.object_info.external_id` | `string` | The external ID (display ID) of this object. unset means that the external ID is the same as the internal ID. |
| `result.object_info.checked_out_version` | [`ObjVerVersion`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjVerVersion/index.md) | The version that is checked out. Version number 0 if the object is not checked out. |
| `result.object_info.checked_out_to_user_id` | `int32` | The ID of the user who has the object checked out. |
| `result.object_info.checked_out_to_user_name` | `string` | The user name of the user who has the object checked out. |
| `result.object_info.checked_out_to_host_name` | `string` | The host name of the computer to which the object was checked out. |
| `result.object_info.checked_out_at_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | The timestamp of the moment the object was checked out. |
| `result.object_info.checked_in_version` | [`ObjVerVersion`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjVerVersion/index.md) | The latest checked-in version. |
| `result.object_info.created_at_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | The time when the object was created (same as the PROPERTYDEF_CREATED propertyvalue). |
| `result.object_info.accessed_by_me_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | Accessed by me timestamp. Parallel operations may cause slight inconsistencies in the returned timestamp in rare cases and the precise value shouldn't be relied upon. The observed timestamp may even roll back. |
| `result.object_info.guid` | `string` | The object GUID, in braces. The same value as `GetObjectGUID` returns. |
| `result.object_info.options` | [`ITEMFLAGS`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ITEMFLAGS/index.md) | Bit flags that provide additional information on the object (e.g. is the object deleted or a stub). |
| `result.object_info.original_vault_guid` | `string` | The GUID of the vault in which the object was originally created. |
| `result.object_info.original_vault_obj_id` | [`ObjID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjID/index.md) | The original objid in the vault in which the object was originally created. |
| `result.object_info.associated_view_id` | [`ItemID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ItemID/index.md) | Identifies the view associated with this object if any. |
| `result.object_info.external_repository_icon_id` | `string` | If not null, identifies the icon of the object. Currently applicable only to unmanaged objects. |
| `result.object_info.primary_view_id` | [`ItemID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ItemID/index.md) | If not null, identifies the primary view of the object that is also the default opening location of the object. Currently applicable only to unmanaged objects. |
| `result.object_info.capabilities` | [`OBJECTCAPABILITYFLAGS`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.OBJECTCAPABILITYFLAGS/index.md) | Bit flags that provide information on the object capabilities. |
| `updated_objects[]` | repeated [`ObjectVersionEx`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjectVersionEx/index.md) | Information about objects that were also updated during the operation. (represented by ObjectVersionEx structs.) |
| `updated_objects[].version_info` | [`ObjectVersion`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjectVersion/index.md) | Object Version information. |
| `updated_objects[].version_info.version` | [`ObjVerVersion`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjVerVersion/index.md) | The version number, as a specific version. |
| `updated_objects[].version_info.display_version` | `string` | The version label to show, if it differs from the version number; empty otherwise. |
| `updated_objects[].version_info.title` | `string` | The title (name) of the object in this version. |
| `updated_objects[].version_info.is_single_file_object` | `bool` | True if the object is a single-file document, which has exactly one file. |
| `updated_objects[].version_info.has_relationships_from_this` | `bool` | Note: this field is deprecated. True if relationships from this object version to one or more documents exist. |
| `updated_objects[].version_info.has_relationships_to_this` | `bool` | Note: this field is deprecated. True if relationships from one or more documents to this object version exist. |
| `updated_objects[].version_info.has_assignments` | `bool` | True if relationships from one or more assignments to this object version exist. |
| `updated_objects[].version_info.last_modified_at_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | When the version was last modified, in UTC. |
| `updated_objects[].version_info.files[]` | repeated [`File`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.File/index.md) | The files of this version. Each `file_ver` can be passed to `DownloadFile_Begin`. |
| `updated_objects[].version_info.object_version_flags` | [`OBJVERFLAGS`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.OBJVERFLAGS/index.md) | Bit flags that provide additional information on the object version. |
| `updated_objects[].version_info.class_id` | `int32` | The class ID of the version. |
| `updated_objects[].version_info.version_guid` | `string` | The GUID of this version. |
| `updated_objects[].version_info.base_properties[]` | repeated [`PropertyValue`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.PropertyValue/index.md) | Not filled by the object read methods; read the property values with `GetObjectVersionAndPropertiesOfMultipleObjects` or `GetProperties`. |
| `updated_objects[].version_info.primary_file` | [`FileID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.FileID/index.md) | File ID of the primary file of a multi-file object, if the object is a multi-file object. |
| `updated_objects[].object_info` | [`ObjectLevelInfo`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjectLevelInfo/index.md) | Object-level information. |
| `updated_objects[].object_info.obj_id` | [`ObjID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjID/index.md) | The object type and ID of the object. |
| `updated_objects[].object_info.external_id_status` | [`ExtIDStatus`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.ExtIDStatus/index.md) | The status of this object's external ID. Values: `EXT_IDSTATUS_UNKNOWN` (0), `EXT_IDSTATUS_EXTERNAL` (1), `EXT_IDSTATUS_INTERNAL` (2), `EXT_IDSTATUS_DISCARDED` (3), `EXT_IDSTATUS_NOT_AVAILABLE` (4), `EXT_IDSTATUS_EXTERNAL_REDUCED` (5). |
| `updated_objects[].object_info.external_id` | `string` | The external ID (display ID) of this object. unset means that the external ID is the same as the internal ID. |
| `updated_objects[].object_info.checked_out_version` | [`ObjVerVersion`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjVerVersion/index.md) | The version that is checked out. Version number 0 if the object is not checked out. |
| `updated_objects[].object_info.checked_out_to_user_id` | `int32` | The ID of the user who has the object checked out. |
| `updated_objects[].object_info.checked_out_to_user_name` | `string` | The user name of the user who has the object checked out. |
| `updated_objects[].object_info.checked_out_to_host_name` | `string` | The host name of the computer to which the object was checked out. |
| `updated_objects[].object_info.checked_out_at_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | The timestamp of the moment the object was checked out. |
| `updated_objects[].object_info.checked_in_version` | [`ObjVerVersion`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjVerVersion/index.md) | The latest checked-in version. |
| `updated_objects[].object_info.created_at_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | The time when the object was created (same as the PROPERTYDEF_CREATED propertyvalue). |
| `updated_objects[].object_info.accessed_by_me_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | Accessed by me timestamp. Parallel operations may cause slight inconsistencies in the returned timestamp in rare cases and the precise value shouldn't be relied upon. The observed timestamp may even roll back. |
| `updated_objects[].object_info.guid` | `string` | The object GUID, in braces. The same value as `GetObjectGUID` returns. |
| `updated_objects[].object_info.options` | [`ITEMFLAGS`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ITEMFLAGS/index.md) | Bit flags that provide additional information on the object (e.g. is the object deleted or a stub). |
| `updated_objects[].object_info.original_vault_guid` | `string` | The GUID of the vault in which the object was originally created. |
| `updated_objects[].object_info.original_vault_obj_id` | [`ObjID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjID/index.md) | The original objid in the vault in which the object was originally created. |
| `updated_objects[].object_info.associated_view_id` | [`ItemID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ItemID/index.md) | Identifies the view associated with this object if any. |
| `updated_objects[].object_info.external_repository_icon_id` | `string` | If not null, identifies the icon of the object. Currently applicable only to unmanaged objects. |
| `updated_objects[].object_info.primary_view_id` | [`ItemID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ItemID/index.md) | If not null, identifies the primary view of the object that is also the default opening location of the object. Currently applicable only to unmanaged objects. |
| `updated_objects[].object_info.capabilities` | [`OBJECTCAPABILITYFLAGS`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.OBJECTCAPABILITYFLAGS/index.md) | Bit flags that provide information on the object capabilities. |

<a id="related"></a>

## Related methods

- [CheckOut](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/CheckOut/index.md): Checks out one object.
- [UploadFile](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/UploadFile/index.md): Uploads a block of new content for an existing file of an object that is checked out to the caller.
- [UploadFileCommit](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/UploadFileCommit/index.md): Completes an upload made with UploadFile and stores it as the new content of the file.
- [CheckIn](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/CheckIn/index.md): Checks in one object.
- [AddObjectWithFiles](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/AddObjectWithFiles/index.md): Creates a new object, optionally with its files, and optionally checks it in.
- [AddObject](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/AddObject/index.md): Creates a new object without files.
