开发者社区> 问答> 正文

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

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

展开
收起
烈血残阳 2016-06-13 10:26:00 9373 0
2 条回答
写回答
取消 提交回答
  • 请问解决了吗?

    2020-08-27 02:12:03
    赞同 展开评论 打赏
  • 一只努力干活儿~~还不粘人的小妖精~

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

    2019-07-17 19:35:13
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
OSS运维进阶实战手册 立即下载
《OSS运维基础实战手册》 立即下载
OSS运维基础实战手册 立即下载