# IRPCObjectOperations.UploadTempFile

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/UploadTempFile/

Badges: `Vault API / core` `write` `session or assertion` `idempotent`

Uploads a block of a file to a temporary upload session on the server. The upload can then be
used as the content of a new object.

- **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/UploadTempFile`
- **HTTP (mf-http-grpc):** `POST /grpc/v1/upload-temp-file`
- **Request:** [`UploadTempFileRequest`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/UploadTempFile/index.md#request)
- **Response:** [`UploadTempFileResponse`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/UploadTempFile/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:** yes
- **Returns metadata structure version:** no
- **Streaming:** none (unary)

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

## Remarks

Upload a file in one or more calls:

1. The first call has `upload_id` 0, `offset` 0 and the `total_size_in_bytes` of the file. It
   returns the new `upload_id`.
2. Further calls pass that `upload_id` and the `offset` of their block.
3. [UploadTempFileCommit](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/UploadTempFileCommit/index.md) completes the
   upload.

The committed upload can be used by
[AddObjectWithFiles](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/AddObjectWithFiles/index.md) (`files` with
`OBJ_FILE_SOURCE_TYPE_UPLOADED_FILE` or `..._UPLOADED_FILES` and the `upload_id`), which consumes
it, and by [DownloadTempFileFromUpload_Begin](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/DownloadTempFileFromUpload_Begin/index.md)
and [GetTextContentForTemporaryFile](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/GetTextContentForTemporaryFile/index.md).
An upload that is not committed cannot be used ("The process cannot access the file because it is
being used by another process.").

**Session.** The upload belongs to the calling login session, on the server that received the
first block; another login session gets "Not found. (The specified upload session <id> does not
exist.)". An upload that is not used for about 10 minutes (server default) is removed: call
[KeepUploadSessionAlive](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/KeepUploadSessionAlive/index.md) at the interval
given in `SessionData.keep_upload_session_alive_interval_in_seconds` if you keep it longer.
Remove uploads you do not use with
[RemoveUploadSession](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/RemoveUploadSession/index.md). Anonymous sessions
cannot upload.

Each request is limited by the server's maximum gRPC message size (48 MiB by default).

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

## Request: UploadTempFileRequest

> 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 |
|---|---|---|
| `upload_id` | `int32` | 0 to start a new upload; the returned ID for the following blocks. |
| `total_size_in_bytes` | `int64` | The size of the whole file. Read only in the first call. |
| `offset` | `int64` | The position of this block in the file. Must be 0 in the first call. Use multiples of 4096 bytes for all blocks but the last. |
| `data` | `bytes` | The bytes of this block. |
| `temp_extension` | [`StringValue`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.StringValue/index.md) | The file name extension of the upload, without the dot (for example "pdf"). Set it in the first call. `DownloadTempFileFromUpload_Begin` returns it as `file_extension`. |
| `temp_extension.value` | `string` | String. |

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

## Response: UploadTempFileResponse

> 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 |
|---|---|---|
| `upload_id` | `int32` | The ID of the upload. |

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

## Related methods

- [UploadTempFileCommit](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/UploadTempFileCommit/index.md): Completes an upload made with UploadTempFile.
- [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.
- [DownloadTempFileFromUpload_Begin](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/DownloadTempFileFromUpload_Begin/index.md): Opens a download session for a committed upload, to read it back or as a PDF, without creating an object.
- [GetTextContentForTemporaryFile](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/GetTextContentForTemporaryFile/index.md): Gets the plain text content of a file uploaded with UploadTempFile.
- [KeepUploadSessionAlive](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/KeepUploadSessionAlive/index.md): Keeps an upload from being removed for inactivity.
- [RemoveUploadSession](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCObjectOperations/RemoveUploadSession/index.md): Removes an upload and its temporary file.
