因公司需要,所以让我去试试使用阿里云的OSS做图片上传下载操作,用代码的,然后的话,我现在大部分按照文档的写了大部分了,图片从相册取到的,然后实现上传代码如下:- (void)upload{
NSString * endpoint = @"http://:oss-tests1.oss-cn-shenzhen.aliyuncs.com";
// oss-tests1.img-cn-shenzhen.aliyuncs.com
// oss-cn-shenzhen.aliyuncs.com
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 = @"OBJ/";
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:channel.oss-tests1.oss-cn-shenzhen.aliyuncs.com/object/OBJ%2F, _kCFStreamErrorDomainKey=1, OriginErrorCode=-1004, NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=http://localhost:channel.oss-tests1.oss-cn-shenzhen.aliyuncs.com/object/OBJ%2F, NSUnderlyingError=0x7fec4383e540 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, _kCFStreamErrorCodeKey=61}
,各位大神谁用个OSS的能不能告知一下,是不是域名错了,但是我这个域名是从域名管理的哪里拿到的,到底哪里有问题呢?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。