开发者社区> 问答> 正文

上传图片 总是报400的错误要不就是403


upload object failed, error: Error Domain=com.aliyun.oss.serverError Code=-400 "(null)" UserInfo={__name=Error, HostId=xzjimg.xzjimg.oss-cn-qingdao.aliyuncs.com, BucketName=xzjimg.xzjimg, Message=The specified bucket is not valid., Code=InvalidBucketName, RequestId=578C994796F2DA846B19520C}


下面的是我上传图片的代码

    NSString *endpoint = @"http://oss-cn-qingdao.aliyuncs.com";
    NSLog(@"self.testModel.AccessKeySecret:%@",self.testModel.AccessKeySecret);
    NSLog(@"self.testModel.AccessKeyId:%@",self.testModel.AccessKeyId);
    
    id<OSSCredentialProvider> credential = [[OSSPlainTextAKSKPairCredentialProvider alloc] initWithPlainTextAccessKey:self.testModel.AccessKeyId secretKey:self.testModel.AccessKeySecret];
    OSSClient *client = [[OSSClient alloc] initWithEndpoint:endpoint credentialProvider:credential];


    
    OSSPutObjectRequest *put = [OSSPutObjectRequest new];
    put.bucketName = @"xzjimg";
    put.objectKey = @"tupian";
    UIImage *image = [UIImage imageNamed:@"451512"];
    put.uploadingData = UIImageJPEGRepresentation(image, 1);


    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;
    }];

展开
收起
daixin 2016-07-18 16:58:32 7532 0
2 条回答
写回答
取消 提交回答
  • 回 1楼xgp的帖子
    是的 endpoint写错了  然后还有一个参数没传上去
    2016-07-19 09:10:14
    赞同 展开评论 打赏
  • 阿里云对象存储(OSS)开发工程师
    看错误是你的endpoint填错了,只需要填"https://oss-cn-qingdao.aliyuncs.com"就可以了,估计你填的是"https://xzjimg.oss-cn-qingdao.aliyuncs.com",但是看代码你的endpoint并没有错,能否确认下你的endpoint是否有改过?
    2016-07-18 17:35:59
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
附件下载测试 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载