
# 上传文件
#### UploadFile()
上传一个文件到OBS，此方法会阻塞线程，直至上传结束。目标OBS桶可在HiLens页面上进行配置，详情请参见[配置数据存储位置](https://support.huaweicloud.com/usermanual-hilens/hilens_02_0041.html#section1)。
- **接口调用**
  HiLensEC hilens::UploadFile(const std::string \& key, const std::string \& filepath, const std::string \& mode)
  
- **参数** **说明**
  表1参数说明 
  | 参数名      | 说明                                    |
  |:---|:---|
  | key      | 上传到obs中的文件名。                          |
  | filepath | 待上传文件的绝对路径。                           |
  | mode     | 上传模式。两种可选："write"-覆盖方式，"append"-追加方式。 |
     
  
- **返回值**
  返回值为0即成功，其他即失败，失败响应参数如[错误码](https://support.huaweicloud.com/sdkreference-hilens/hilens_03_0048.html)所示。
  
#### UploadFileAsync()
异步上传一个文件，会立即返回。
- **接口调用**
  HiLensEC hilens::UploadFileAsync(const std::string \& key, const std::string \& filepath, const std::string \& mode, void(\*)(int) callback = NULL)
  
- **参数** **说明**
  表2参数说明 
  | 参数名      | 说明                        |
  |:---|:---|
  | key      | 上传到obs中的文件名。              |
  | filepath | 待上传文件的绝对路径。               |
  | mode     | 上传模式，"write" or "append"。 |
  | callback | 回调函数。                     |
     
  
- **返回值**
  返回值为0即成功，其他即失败，失败响应参数如[错误码](https://support.huaweicloud.com/sdkreference-hilens/hilens_03_0048.html)所示。
  
 
