> For the complete documentation index, see [llms.txt](https://docs.swanchain.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.swanchain.io/bulders/app-developer/store-and-retrieve-a-file-with-swan-storage/3.upload-files-and-folders.md).

# 3.Upload Files and Folders

### 3.1 Upload a single file

`upload_file(bucket_name, object_name, file_path, replace=False)`

Uploads a file to a bucket. Use the `bucket_name` to select the bucket, and `object_name` to select the path and file name of the uploaded file. `file_path` is the local path of the file.

```python
from swan_mcs import APIClient, BucketAPI
mcs_api = APIClient("<API_KEY>")
bucket_client = BucketAPI(mcs_api)

# Object name is the destination path you want to upload to the bucket
# For example, if you want to upload the testfile.json file to path 111/222 in the TEST bucket, you would write: 
# bucket_client.upload_file("TEST", "111/222/testfile.json", "<FILE_PATH>")
bucket_client.upload_file("<BUCKET_NAME>", "<OBJECT_NAME>", "<FILE_PATH>")
```

**Parameters**

* **bucket\_name**: The name of the bucket
* **object\_name:** The object name of the file ex. `'folder1/file.png'` will upload the file as `file.png` inside `bucket_name/folder1`
* **file\_path:** The local file path
* **replace:** File's of the same name cannot be uploaded. When replace is set to True, it will overwrite the previous file of the same name.

**Return**

Returns a File Object

### 3.2 Upload a folder

Uploads `folder_path` as an MCS folder under `bucket_name`/`object_name`

```python
from swan_mcs import APIClient, BucketAPI
mcs_api = APIClient("<API_KEY>")
bucket_client = BucketAPI(mcs_api)

bucket_client.upload_folder("<BUCKET_NAME>", "<OBJECT_NAME>", "<FOLDER_PATH>")
```

**Parameters**

* bucket\_name: The name of the bucket
* object\_name: The object name for the folder
* folder\_path: Local path of your folder

**Return**

Returns a list of File Objects

### 3.3 Upload as IPFS folder

Uploads `folder_path` as an IPFS folder to MCS. This gives the folder its own CID, sharable to others.

```python
from swan_mcs import APIClient, BucketAPI
mcs_api = APIClient("<API_KEY>")
bucket_client = BucketAPI(mcs_api)

bucket_client.upload_ipfs_folder("<BUCKET_NAME>", "<OBJECT_NAME>", "<FOLDER_PATH>")
```

**Parameters**

* bucket\_name: The name of the bucket
* object\_name: The object name for the folder
* folder\_path: Local path of your folder

**Return**

Returns a File Object for your IPFS folder
