
# 上传对象
本示例用于将本地文件上传到桶名为"bucketname"里，名称为"objectname"。
代码示例如下：
```
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"fileName" ofType:@"Type"];
OBSPutObjectWithFileRequest *request = [[OBSPutObjectWithFileRequest alloc]initWithBucketName:@"bucketname" objectKey:@"objectname" uploadFilePath:filePath];
// 上传进度
request.uploadProgressBlock = ^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
    NSLog(@"%0.1f%%",(float)floor((totalBytesExpectedToSend > 0) ? (totalBytesSent*10000/totalBytesExpectedToSend) : 0)/100);
};
// 上传文件
[client putObject:request completionHandler:^(OBSPutObjectResponse *response, NSError *error){
    if (response.etag) {
        NSLog(@"%@",response.etag);
    }
}];
```
![](https://support.huaweicloud.com/sdk-ios-devg-obs/public_sys-resources/notice_3.0-zh-cn.png)
当前SDK的文件上传接口（OBSPutObjectWithFileRequest、OBSUploadFileRequest）的uploadFilePath参数仅接受NSString类型的文件路径，不支持直接传入\[NSURL fileURLWithPath:@"xxx"\]构造的NSURL对象。如需使用NSURL，请先通过\[fileURL path\]获取文件路径字符串，再传入uploadFilePath参数。
![](https://support.huaweicloud.com/sdk-ios-devg-obs/public_sys-resources/note_3.0-zh-cn.png)
- 更多上传对象的信息，请参见[上传对象](https://support.huaweicloud.com/sdk-ios-devg-obs/obs_27_0400.html)。
 
