开发者社区> 问答> 正文

ios OSS上传图片很慢

刚开始用阿里的OSS上传图片,结果2M大的图片 差不多用了1分钟才传成功。 如何能快一点? 下面是我的上传代码

  • (void)uploadObjectAsyncContentType:(NSString)contentType andName:(NSString)fileName data:(NSData*)myData{

    OSSPutObjectRequest * put = [OSSPutObjectRequest new];
    
    put.bucketName =myBucketName;
    
     NSString *objectKeyFile = [NSString stringWithFormat:@"5678bde87fef6a300b000029/%@/%@",[self currentTime:@"YYYYMMdd"],fileName];
    put.objectKey = objectKeyFile;
    
    put.uploadingData = myData; // 直接上传NSData
    
    put.uploadProgress = ^(int64_t bytesSent,int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
    

    // NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
    NSInteger fir = totalByteSent;
    NSInteger all = totalBytesExpectedToSend;
    CGFloat rate = 1.0*fir/all;
    NSLog(@"比例 = %lf.2",rate);

    };
    OSSTask * putTask = [client putObject:put];
    // 上传阿里云   
    [putTask continueWithBlock:^id(OSSTask *task) {
    

    if (!task.error) {

    
    NSLog(@"upload object success!");
    NSLog(@"task.result == %@",task.result);
    

    } else {

    NSLog(@"upload object failed, error: %@" , task.error);
    

    }
    return nil;

    }]; 

    }

展开
收起
觉醒的鬼厉 2017-07-07 13:44:30 5037 0
1 条回答
写回答
取消 提交回答
  • 代码层面没有影响。考虑:

    1. 提高网速
    2. 提高租用的带宽
    2019-07-17 21:22:29
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载