Uploading an object
This example uploads a local file to bucket bucketname as object objectname.
Sample code:
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"fileName" ofType:@"Type"];
OBSPutObjectWithFileRequest *request = [[OBSPutObjectWithFileRequest alloc]initWithBucketName:@"bucketname" objectKey:@"objectname" uploadFilePath:filePath];
// Query the upload progress.
request.uploadProgressBlock = ^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
NSLog(@"%0.1f%%",(float)floor((totalBytesExpectedToSend > 0) ? (totalBytesSent*10000/totalBytesExpectedToSend) : 0)/100);
};
// Upload a file.
[client putObject:request completionHandler:^(OBSPutObjectResponse *response, NSError *error){
if (response.etag) {
NSLog(@"%@",response.etag);
}
}];
In the current SDK, the uploadFilePath parameter of the file upload APIs (OBSPutObjectWithFileRequest and OBSUploadFileRequest) only accepts file paths of the NSString type. Directly passing an NSURL object created with [NSURL fileURLWithPath:@"xxx"] is not supported. To use NSURL, obtain the file path string through [fileURL path] and then pass it to the uploadFilePath parameter.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot
