我尝试使用阿里云的OSS iOS版的,用demo上传一张图片,但是都不成功,以下是我的代码(图片源没问题):
NSString * endpoint = @"http://:oss-tests1.img-cn-shenzhen.aliyuncs.com/OBJ";
//我不清楚这个endpoint写错了么?域名我从控制器拿到两个内网外网的,都一样结果!!!
id<OSSCredentialProvider> credential = [[OSSPlainTextAKSKPairCredentialProvider alloc] initWithPlainTextAccessKey:@"AccessKey"
secretKey:@"secretKey"];
OSSClient * client = [[OSSClient alloc] initWithEndpoint:endpoint credentialProvider:credential];
OSSPutObjectRequest * put = [OSSPutObjectRequest new];
NSData * data = UIImageJPEGRepresentation(_image, 1.0);
put.bucketName = @"oss-tests1";
put.objectKey = @"ty.png";
//这个objectKey是指什么?文件夹名字还是上传后的文件名字?
put.uploadingData = data;
put.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
};
OSSTask * putTask = [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;
}];
这样的代码返回了下面的信息:
upload object failed, error: Error Domain=com.aliyun.oss.clientError Code=6 "Could not connect to the server." UserInfo={NSErrorFailingURLKey=http://localhost:oss-tests1.img-cn-shenzhen.aliyuncs.com/OBJ/ty.png, _kCFStreamErrorDomainKey=1, OriginErrorCode=-1004, NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=http://localhost:oss-tests1.img-cn-shenzhen.aliyuncs.com/OBJ/ty.png, NSUnderlyingError=0x7f9da603cee0 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, _kCFStreamErrorCodeKey=61}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。