# POST /v1/templates/upload

> Upload a DOC, DOCX, RTF or TX template as a Base64 string to the template storage under a templateName; a file of the same name is overwritten.

- **Product:** ReportingCloud
- **Section:** Documentation
- **Kind:** Endpoint
- **Path:** ReportingCloud > API Reference > Web API > Templates > /upload > POST /v1/templates/upload
- **2475 words**
- **Web URL:** https://docs.textcontrol.com/reporting-cloud/reference/web-api/templates/upload/post/
- **LLMs URL:** https://docs.textcontrol.com/reporting-cloud/reference/web-api/templates/upload/post/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/reporting-cloud/reference/web-api/templates/upload/post/llms-full.txt

---

`POST` `https://api.reporting.cloud/v1/templates/upload`

### Description

Stores a template in the template storage, where merge and the other methods find it by its name. The query names the template, and the body is the file as a Base64 string in a JSON string. The supported formats are Microsoft Word (.docx and .doc), Rich Text Format (.rtf) and TX Text Control (.tx), and the extension of the name must match the format of the file. An upload under a stored name replaces that template; names are matched regardless of case. See [Managing Templates](https://docs.textcontrol.com/reporting-cloud/document-processing/templates/llms-full.txt).

> Warning
>
> **Template Storage Quota.** Each successful upload under a new name counts 1 against the template storage quota. An upload that replaces a stored template doesn't count, and deleting a template frees its place. [Plans and Licensing](https://docs.textcontrol.com/reporting-cloud/overview/licensing/llms-full.txt) lists the quota of each plan.

### Examples

#### HTTP

Request:

```bash
curl -u username:password \
  -H "Content-Type: application/json" \
  -d "\"CAcBAA4AAAAAAAAAAAAA...==\"" \
  -X POST "https://api.reporting.cloud/v1/templates/upload?templateName=test.tx"
```

#### C#

Request:

```csharp
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using TXTextControl.ReportingCloud;

class RCSamples
{

    public static void UploadTemplate(string templateName)
    {
        ReportingCloud rc = new ReportingCloud(
            "username",
            "password",
            new Uri("https://api.reporting.cloud"));

        try
        {
            byte[] data = File.ReadAllBytes(templateName);
            rc.UploadTemplate(templateName, data);
            Console.WriteLine(templateName + " has been uploaded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("An error occurred: " + e.Message);
        }
    }
}
```

Results:

```text
test.tx has been uploaded.
```

#### Java

Request:

```java
import com.textcontrol.reportingcloud.ReportingCloud;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class ReportingCloudSample {
    public static void main(String[] args) throws IOException {
        ReportingCloud r = new ReportingCloud("username", "password");
        byte[] templateData = Files.readAllBytes(Paths.get("test.tx"));
        r.uploadTemplate("test.tx", templateData);
    }
}
```

#### Ruby

Request:

```ruby
#!/usr/bin/env ruby

require "txtextcontrol/reportingcloud"
require "base64"

reporting_cloud = TXTextControl::ReportingCloud::ReportingCloud.new("username", "password")
template_data = File.open(File.dirname(__FILE__) + "/test.tx", "rb") { |f| f.read }
template_data_b64 = Base64.strict_encode64(template_data)
reporting_cloud.upload_template("test.tx", template_data_b64)
```

#### PHP

Request:

```php
<?php

require_once __DIR__ . '/vendor/autoload.php';

use TextControl\ReportingCloud\ReportingCloud;

$reportingCloud = new ReportingCloud([
    'api_key' => (string) getenv('REPORTINGCLOUD_API_KEY'),
]);

$templateFilename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'test.tx';

var_dump($reportingCloud->uploadTemplate($templateFilename));
```

Results:

```text
bool(true)
```

### Authorization

This endpoint requires a "ReportingCloud-APIKey" or a "Basic" user authorization to access the user account, data and templates. Only one of these two methods is required.

[API Keys](https://docs.textcontrol.com/reporting-cloud/installation/api-keys/llms-full.txt) describes how to create an API key, and [Authentication](https://docs.textcontrol.com/reporting-cloud/document-processing/authentication/llms-full.txt) explains both header forms.

#### ReportingCloud-APIKey

| Header field | Description |
|---|---|
| Authorization | **Required**. A valid ReportingCloud account is required. The Authorization field is constructed as follows: An API key needs to be generated in the portal or with [PUT /v1/account/apikey](https://docs.textcontrol.com/reporting-cloud/reference/web-api/account/apikey/put/llms-full.txt). The authorization method and a space, "ReportingCloud-APIKey ", is then put before the actual API key string. For example: `Authorization: ReportingCloud-APIKey oMDM4MrAqL9QEOpyzupnQW5NjvCNtvE5cVDaaLqxI` |

#### Basic

| Header field | Description |
|---|---|
| Authorization | **Required**. A valid ReportingCloud account is required. The Authorization field is constructed as follows: The user name and password are combined into a string separated by a colon, for example `username:password`. The resulting string is encoded using the RFC2045-MIME variant of Base64, except not limited to 76 char/line. The authorization method and a space, "Basic ", is then put before the encoded string. For example: `Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l` |

### Request Parameters

| Name | Type | Value | Optional |
|---|---|---|---|
| templateName | String | The filename of the template in the template storage, with the extension .doc, .docx, .rtf or .tx in any case and at most 207 characters. Existing files with the same filename will be overwritten. Filenames are not case-sensitive: a stored template whose filename differs only in case is overwritten too and keeps its stored filename. | no |

### Request Payload

| Type | Value |
|---|---|
| Base64 encoded string | A document encoded as a Base64 string and sent as a JSON string, in double quotes, with the Content-Type application/json. Supported document formats are .doc, .docx, .rtf and .tx, and the document must be in the format that the extension of templateName names. |

### Success Response

| Status | Description |
|---|---|
| 201 | On success, the HTTP status code in the response header is 201 (Created). The response body contains no data. |

### Error Response

| Status | Description |
|---|---|
| 400 | A 400 (Bad Request) is returned, if the extension of templateName is not .doc, .docx, .rtf or .tx, or if the template has a wrong format, isn't in the format of its extension or is corrupted. |
| 403 | A 403 (Forbidden) is returned, if the user is not authorized or the template storage quota is exceeded. The same 403 ("Template quota exceeded") is returned for a templateName that has more than 207 characters or contains # or /. |
| 404 | A 404 (Not Found) is returned, if a required query parameter is missing. |
| 405 | A 405 (Method Not Allowed) is returned, if the request uses another HTTP method than POST. The Allow header of the response names POST. |
| 411 | A 411 (Length Required) is returned, if the request has neither a body nor a Content-Length header. |
| 415 | A 415 (Unsupported Media Type) is returned, if the request has a body but no Content-Type header, or a Content-Type such as text/plain that the endpoint doesn't read. Send Content-Type: application/json. |
| 500 | A 500 (Internal Server Error) is returned, if the request has no Authorization header, an empty one or one that is not the authorization method, a space and the credentials, or if the request body is not a JSON string of valid Base64 data or templateName is empty. |

---

## Nearby

- **Previous:** [/v1/templates/upload](https://docs.textcontrol.com/reporting-cloud/reference/web-api/templates/upload/llms-full.txt)
- **Next:** [Account](https://docs.textcontrol.com/reporting-cloud/reference/web-api/account/llms-full.txt)
