> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://uploadcare.com/docs/llms.txt.

# Copy file to remote storage

POST https://api.uploadcare.com/files/remote_copy/
Content-Type: application/json

POST requests are used to copy original files or their modified versions to the S3 bucket.

Source files MAY either be stored or just uploaded and MUST NOT be deleted.

Copying of large files is not supported at the moment. File size MUST NOT exceed 5 GB.


Reference: https://uploadcare.com/docs/api/rest/file/create-remote-copy

## Authentication

- `Authorization` header (required) — Every request made to `https://api.uploadcare.com/` MUST be signed. HTTPS SHOULD be used with any authorization scheme. Requests MUST contain the `Authorization` header defining `auth-scheme` and `auth-param`: `Authorization: auth-scheme auth-param`. Every request MUST contain the `Accept` header identifying the REST API version: `Accept: application/vnd.uploadcare-v0.7+json`. There are two available authorization schemes: * For production: `Uploadcare`, a scheme where a `signature`, not your Secret API Key MUST be specified. Signatures SHOULD be generated on backend. * For quick tests: `Uploadcare.Simple`, a simple scheme where your [Secret API Key](https://app.uploadcare.com/projects/-/api-keys/) MUST be specified in every request's `auth-param`.

## Request

### Headers

- `Accept` (string, required) — Version header.

### Body (application/json)

This endpoint expects an object.

- `source` (string, required) — A CDN URL or just UUID of a file subjected to copy.
- `target` (string, required) — Identifies a custom storage name related to your project. It implies that you are copying a file to a specified custom storage. Keep in mind that you can have multiple storages associated with a single S3 bucket.
- `make_public` (boolean, optional, default: true) — MUST be either `true` or `false`. The `true` value makes copied files available via public links, `false` does the opposite.
- `pattern` (enum, optional, default: ${default}) — The parameter is used to specify file names Uploadcare passes to the S3 bucket. If the parameter is omitted, your S3 bucket pattern is used. Use any combination of allowed values. Parameter values: * `${default}` = `${uuid}/${auto_filename}` * `${auto_filename}` = `${filename}${effects}${ext}` * `${effects}` = processing operations put into a CDN URL * `${filename}` = original filename without extension * `${uuid}` = file UUID * `${ext}` = file extension, including period, e.g. .jpg
  - Allowed values: `${default}`, `${auto_filename}`, `${effects}`, `${filename}`, `${uuid}`, `${ext}`

## Response

### 200

Destination file with that name already exists. Check the `pattern` parameter.

- `type` (string, optional, default: url)
- `result` (string, optional) — URL with an s3 scheme. Your bucket name is put as a host, and an s3 object path follows.

### 201

The file was copied successfully. HTTP response contains `result` field with the URL of the file on the remote storage.

- `type` (string, optional, default: url)
- `result` (string, optional) — URL with an s3 scheme. Your bucket name is put as a host, and an s3 object path follows.

## Errors

### 400 Bad Request Error

Simple HTTP auth. on HTTP or file copy errors.

- `CreateRemoteCopyRequestBadRequestError`
  - simpleAuthHTTPForbidden: simpleAuthHTTPForbidden

### 401 Unauthorized Error

Authorization errors.

- `detail` (enum, optional)
  - Allowed values: `Incorrect authentication credentials.`, `Public key {public_key} not found.`, `Secret key not found.`, `Invalid signature. Please check your Secret key.`

### 406 Not Acceptable Error

Invalid version header `Accept` for this endpoint.

- `detail` (string, optional, default: Incorrect Accept header provided. Make sure to specify API version. Refer to REST API docs for details.)

### 429 Too Many Requests Error

Request was throttled.

- `detail` (string, optional)

## Types

### simpleAuthHTTPForbidden

- `detail` (string, optional, default: Simple authentication over HTTP is forbidden. Please, use HTTPS or signed requests instead.)

## Examples

### Create Remote Copy

**Request**

```json
{
  "source": "03ccf9ab-f266-43fb-973d-a6529c55c2ae",
  "target": "mytarget"
}
```

**Response**

```json
{
  "type": "url",
  "result": "s3://mybucket/03ccf9ab-f266-43fb-973d-a6529c55c2ae/image.png"
}
```

**SDK Code**

```javascript JS
import {
  copyFileToRemoteStorage,
  UploadcareSimpleAuthSchema,
} from '@uploadcare/rest-client';

const uploadcareSimpleAuthSchema = new UploadcareSimpleAuthSchema({
  publicKey: 'YOUR_PUBLIC_KEY',
  secretKey: 'YOUR_SECRET_KEY',
});

const result = await copyFileToRemoteStorage(
  {
    source: '1bac376c-aa7e-4356-861b-dd2657b5bfd2',
    target: 'custom_storage_connected_to_the_project',
  },
  { authSchema: uploadcareSimpleAuthSchema }
)

```

```php PHP
<?php
$configuration = Uploadcare\Configuration::create((string) $_ENV['UPLOADCARE_PUBLIC_KEY'], (string) $_ENV['UPLOADCARE_SECRET_KEY']);

$api = (new Uploadcare\Api($configuration))->file();
$result = $api->copyToRemoteStorage('03ccf9ab-f266-43fb-973d-a6529c55c2ae', true);
echo \sprintf('File \'%s\' copied to local storage', $result);

```

```python Python
from pyuploadcare import Uploadcare
uploadcare = Uploadcare(public_key='YOUR_PUBLIC_KEY', secret_key='YOUR_SECRET_KEY')

file = uploadcare.file("1bac376c-aa7e-4356-861b-dd2657b5bfd2")
r_copied_file = file.create_remote_copy(
    target='custom_storage_connected_to_the_project',
    make_public=True,
    pattern='${uuid}/${filename}${ext}',
)

```

```ruby Ruby
require 'uploadcare'
Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'

source_object = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
target = 'custom_storage_connected_to_the_project'
copied_file_url = Uploadcare::File.remote_copy(source_object, target, make_public: true)
puts copied_file_url

```

```swift Swift
import Uploadcare

let uploadcare = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY", secretKey: "YOUR_SECRET_KEY")

let response = try await uploadcare.copyFileToRemoteStorage(source: "03ccf9ab-f266-43fb-973d-a6529c55c2ae", target: "mytarget", pattern: .uuid)
print(response)

```

```kotlin Kotlin
import com.uploadcare.android.library.api.UploadcareClient

val uploadcare = UploadcareClient(publicKey = "YOUR_PUBLIC_KEY", secretKey = "YOUR_SECRET_KEY")

val copyFile = uploadcare.copyFileRemoteStorage(
    source = "1bac376c-aa7e-4356-861b-dd2657b5bfd2",
    target = "custom_storage_connected_to_the_project"
)
Log.d("TAG", copyFile.toString())

```

```go Create Remote Copy
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.uploadcare.com/files/remote_copy/"

	payload := strings.NewReader("{\n  \"source\": \"03ccf9ab-f266-43fb-973d-a6529c55c2ae\",\n  \"target\": \"mytarget\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Accept", "application/vnd.uploadcare-v0.7+json")
	req.Header.Add("Authorization", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```java Create Remote Copy
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.uploadcare.com/files/remote_copy/")
  .header("Accept", "application/vnd.uploadcare-v0.7+json")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"source\": \"03ccf9ab-f266-43fb-973d-a6529c55c2ae\",\n  \"target\": \"mytarget\"\n}")
  .asString();
```

```csharp Create Remote Copy
using RestSharp;

var client = new RestClient("https://api.uploadcare.com/files/remote_copy/");
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/vnd.uploadcare-v0.7+json");
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"source\": \"03ccf9ab-f266-43fb-973d-a6529c55c2ae\",\n  \"target\": \"mytarget\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

### Create Remote Copy

**Request**

```json
{
  "source": "03ccf9ab-f266-43fb-973d-a6529c55c2ae",
  "target": "mytarget"
}
```

**Response**

```json
{
  "type": "url",
  "result": "s3://mybucket/03ccf9ab-f266-43fb-973d-a6529c55c2ae/image.png"
}
```

**SDK Code**

```javascript JS
import {
  copyFileToRemoteStorage,
  UploadcareSimpleAuthSchema,
} from '@uploadcare/rest-client';

const uploadcareSimpleAuthSchema = new UploadcareSimpleAuthSchema({
  publicKey: 'YOUR_PUBLIC_KEY',
  secretKey: 'YOUR_SECRET_KEY',
});

const result = await copyFileToRemoteStorage(
  {
    source: '1bac376c-aa7e-4356-861b-dd2657b5bfd2',
    target: 'custom_storage_connected_to_the_project',
  },
  { authSchema: uploadcareSimpleAuthSchema }
)

```

```php PHP
<?php
$configuration = Uploadcare\Configuration::create((string) $_ENV['UPLOADCARE_PUBLIC_KEY'], (string) $_ENV['UPLOADCARE_SECRET_KEY']);

$api = (new Uploadcare\Api($configuration))->file();
$result = $api->copyToRemoteStorage('03ccf9ab-f266-43fb-973d-a6529c55c2ae', true);
echo \sprintf('File \'%s\' copied to local storage', $result);

```

```python Python
from pyuploadcare import Uploadcare
uploadcare = Uploadcare(public_key='YOUR_PUBLIC_KEY', secret_key='YOUR_SECRET_KEY')

file = uploadcare.file("1bac376c-aa7e-4356-861b-dd2657b5bfd2")
r_copied_file = file.create_remote_copy(
    target='custom_storage_connected_to_the_project',
    make_public=True,
    pattern='${uuid}/${filename}${ext}',
)

```

```ruby Ruby
require 'uploadcare'
Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'

source_object = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
target = 'custom_storage_connected_to_the_project'
copied_file_url = Uploadcare::File.remote_copy(source_object, target, make_public: true)
puts copied_file_url

```

```swift Swift
import Uploadcare

let uploadcare = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY", secretKey: "YOUR_SECRET_KEY")

let response = try await uploadcare.copyFileToRemoteStorage(source: "03ccf9ab-f266-43fb-973d-a6529c55c2ae", target: "mytarget", pattern: .uuid)
print(response)

```

```kotlin Kotlin
import com.uploadcare.android.library.api.UploadcareClient

val uploadcare = UploadcareClient(publicKey = "YOUR_PUBLIC_KEY", secretKey = "YOUR_SECRET_KEY")

val copyFile = uploadcare.copyFileRemoteStorage(
    source = "1bac376c-aa7e-4356-861b-dd2657b5bfd2",
    target = "custom_storage_connected_to_the_project"
)
Log.d("TAG", copyFile.toString())

```

```go Create Remote Copy
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.uploadcare.com/files/remote_copy/"

	payload := strings.NewReader("{\n  \"source\": \"03ccf9ab-f266-43fb-973d-a6529c55c2ae\",\n  \"target\": \"mytarget\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Accept", "application/vnd.uploadcare-v0.7+json")
	req.Header.Add("Authorization", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```java Create Remote Copy
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.uploadcare.com/files/remote_copy/")
  .header("Accept", "application/vnd.uploadcare-v0.7+json")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"source\": \"03ccf9ab-f266-43fb-973d-a6529c55c2ae\",\n  \"target\": \"mytarget\"\n}")
  .asString();
```

```csharp Create Remote Copy
using RestSharp;

var client = new RestClient("https://api.uploadcare.com/files/remote_copy/");
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/vnd.uploadcare-v0.7+json");
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"source\": \"03ccf9ab-f266-43fb-973d-a6529c55c2ae\",\n  \"target\": \"mytarget\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```