id credential = [[OSSFederationCredentialProvider alloc] initWithFederationTokenGetter:^OSSFederationToken *{
OSSFederationToken * token = [OSSFederationToken new];
token.tAccessKey = accessKey;
token.tSecretKey = secretKey;
token.tToken = tToken;
return token;
}];
OSSClientConfiguration * conf = [OSSClientConfiguration new];
conf.maxRetryCount = 2;
conf.timeoutIntervalForRequest = 30;
self.client = [[OSSClient alloc] initWithEndpoint:ENDPOINT credentialProvider:credential clientConfiguration:conf];
OSSPutObjectRequest * put = [OSSPutObjectRequest new];
// 必填字段
put.bucketName = bucketName;
put.objectKey = key;
put.uploadingData = data;
if (option) {
put.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
// 当前上传段长度、当前已经上传总长度、一共需要上传的总长度
};
}
if (option.callbackParam) {
put.callbackParam = option.callbackParam;
}
if (option.params) {
put.callbackVar = option.params;
}
OSSTask * putTask = [self.client putObject:put];
[putTask continueWithBlock:^id(OSSTask *task) {
if (!task.error) {
NSLog(@"upload object success!");
} else {
NSLog(@"upload object failed, error: %@" , task.error);
}
return nil;
}];
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。