开发者社区> 问答> 正文

iOS用OSS上传一张图片,然后提示这些错误,小白不理解如何解决,求大神帮看看!

烈血残阳 2016-06-13 10:26:00 4854

因公司需要,所以让我去试试使用阿里云的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的能不能告知一下,是不是域名错了,但是我这个域名是从域名管理的哪里拿到的,到底哪里有问题呢?

分享到
取消 提交回答
全部回答(1)
  • little09
    2019-07-17 19:35:13

    您好 具体技术问题可以添加 OSS技术交流群:1421921057 进行提问

    0 1
+ 订阅

时时分享云计算技术内容,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。

推荐文章
相似问题