> 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 local storage

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

POST requests are used to copy original files or their modified versions to a default storage.

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

Copying of large files is not supported at the moment. If the file CDN URL includes transformation operators, its size MUST NOT exceed 100 MB. If not, the size MUST NOT exceed 5 GB.

Note: In the immediate 201 response, the `result.size` can be `0` and the `result.mime_type` can be `application/octet-stream`. This indicates the copy has been initiated but is not yet completed.
Once the copy finishes, fetching the file info (e.g., `GET /files/{uuid}/`) will return the actual size and MIME type.

Reference: https://uploadcare.com/docs/api/rest/file/create-local-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.
- `store` (enum, optional, default: false) — The parameter only applies to the Uploadcare storage and MUST be either true or false.
  - Allowed values: `true`, `false`
- `metadata` (FilesLocalCopyPostRequestBodyContentApplicationJsonSchemaMetadata, optional) — Arbitrary additional metadata.

## Response

### 201

The file was copied successfully. HTTP response contains `result` field with information about the copy.

- `type` (string, optional, default: file)
- `result` (fileCopy, optional)

## Errors

### 400 Bad Request Error

Possible errors for file copy endpoint.

- `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.`

### 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

### FilesLocalCopyPostRequestBodyContentApplicationJsonSchemaMetadata

Arbitrary additional metadata.

### fileCopy

- `datetime_removed` (datetime, required, nullable) — Date and time when a file was removed, if any.
- `datetime_stored` (datetime, required, nullable) — Date and time of the last store request, if any.
- `datetime_uploaded` (datetime, required) — Date and time when a file was uploaded.
- `is_image` (boolean, required) — Is file is image.
- `is_ready` (boolean, required) — Is file is ready to be used after upload.
- `mime_type` (string, required) — File MIME-type. In the immediate response after starting a local copy, it can be `application/octet-stream` until the copy completes.
- `original_file_url` (string, required, nullable) — Publicly available file CDN URL. Available if a file is not deleted.
- `original_filename` (string, required) — Original file name taken from uploaded file.
- `size` (enum, required) — File size in bytes. In the immediate response after starting a local copy, it can be `0` until the copy completes.
  - Allowed values: `0`
- `url` (string, required) — API resource URL for a particular file.
- `uuid` (string, required) — File UUID.
- `variations` (any, required)
- `content_info` (any, required)
- `metadata` (metadata, required) — Arbitrary metadata associated with a file.
- `tags` (list of string, optional) — Ordered list of string tags associated with the file. Empty array if no tags are set.

### metadata

Arbitrary metadata associated with a file.

## Examples

**Request**

```json
{
  "source": "03ccf9ab-f266-43fb-973d-a6529c55c2ae",
  "store": "true",
  "metadata": {
    "pet": "cat",
    "subsystem": "uploader"
  }
}
```

**Response**

```json
{
  "type": "file",
  "result": {
    "datetime_removed": "2024-01-15T09:30:00Z",
    "datetime_stored": "2024-01-15T09:30:00Z",
    "datetime_uploaded": "2024-01-15T09:30:00Z",
    "is_image": true,
    "is_ready": true,
    "mime_type": "image/jpeg",
    "original_file_url": "string",
    "original_filename": "EU_4.jpg",
    "size": 0,
    "url": "string",
    "uuid": "575ed4e8-f4e8-4c14-a58b-1527b6d9ee46",
    "variations": null,
    "content_info": null,
    "metadata": {},
    "tags": [
      "cat",
      "animal"
    ]
  }
}
```

**SDK Code**

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

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

const result = await copyFileToLocalStorage(
  {
    source: '1bac376c-aa7e-4356-861b-dd2657b5bfd2',
    store: true,
  },
  { 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();
$fileInfo = $api->copyToLocalStorage('03ccf9ab-f266-43fb-973d-a6529c55c2ae', true);
echo \sprintf('File \'%s\' copied to local storage', $fileInfo->getUuid());

```

```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")
copied_file = file.create_local_copy(store=True)

```

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

source = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
copied_file = Uploadcare::File.local_copy(source, store: true)
puts copied_file.uuid

```

```swift Swift
import Uploadcare

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

let response = try await uploadcare.copyFileToLocalStorage(source: "1bac376c-aa7e-4356-861b-dd2657b5bfd2")
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.copyFileLocalStorage(source = "1bac376c-aa7e-4356-861b-dd2657b5bfd2")
Log.d("TAG", copyFile.toString())

```

```go Create Local Copy
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"source\": \"03ccf9ab-f266-43fb-973d-a6529c55c2ae\",\n  \"store\": \"true\",\n  \"metadata\": {\n    \"pet\": \"cat\",\n    \"subsystem\": \"uploader\"\n  }\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 Local Copy
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.uploadcare.com/files/local_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  \"store\": \"true\",\n  \"metadata\": {\n    \"pet\": \"cat\",\n    \"subsystem\": \"uploader\"\n  }\n}")
  .asString();
```

```csharp Create Local Copy
using RestSharp;

var client = new RestClient("https://api.uploadcare.com/files/local_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  \"store\": \"true\",\n  \"metadata\": {\n    \"pet\": \"cat\",\n    \"subsystem\": \"uploader\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```