# 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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.swanchain.io/bulders/app-developer/store-and-retrieve-a-file-with-swan-storage/3.upload-files-and-folders.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
