# 上传数据
<subtitle>将本地的单个文件或整个目录上传到 Volume。</subtitle>

您可以使用 `write_file()` 方法将数据上传到 Volume。传入文件对象时，SDK 会分块流式上传，不会一次性将整个文件读入内存。

## 上传单个文件

```python
from ucloud_sandbox import Volume

volume = Volume.connect('volume-id')

# 从本地文件系统读取文件
with open('/local/path', 'rb') as file:
    # 上传到 Volume
    volume.write_file('/path/in/volume', file)
```

## 上传目录或多个文件

```python
import os
from ucloud_sandbox import Volume

volume = Volume.connect('volume-id')

directory_path = '/local/dir'

for filename in os.listdir(directory_path):
    file_path = os.path.join(directory_path, filename)

    # 跳过子目录
    if not os.path.isfile(file_path):
        continue

    with open(file_path, 'rb') as file:
        volume.write_file(f'/upload/{filename}', file)
```
