Giter Club home page Giter Club logo

qiniu_upload's Introduction

QiniuUpload

CocoaPods Compatible Platform

qiniu_upload 是一款支持七牛云存储的 iOS/macOS sdk。

qiniu_upload 除了文件上传等基本功能完,还实现了多文件队列上传。

qiniu_upload 转入了维护,想去写个 UploadKit。

Done

  • 减小内存占用,清除内存泄露
  • 支持多种数据来源,包括 ALAsset, NSData,NSFileManager
  • 支持 NSInputStream 方式上传
  • 支持并发上传
  • 支持版本更新在开发环境中提示
  • Remove all warnings
  • Remove AFNetWorking support

如何开始


CocoaPods

Podfile

    pod "QiniuUpload"

手动安装

复制Classes目录下的类到工程项目中就行了。

开始编码

QiniuToken

首先要初始化一个 QiniuToken。scope, secretKey, accessKey 注册七牛后官方都会给出

    [QiniuToken registerWithScope:@"your_scope" SecretKey:@"your_secretKey" Accesskey:@"your_accesskey"];

这样初始化,一个 Token 的默认有效生命周期是5分钟,如果你想自定义生命周期的话,可以这样初始化

    [QiniuToken registerWithScope:@"your_scope" SecretKey:@"your_secretKey" Accesskey:@"your_accesskey" TimeToLive:60]

生成一个上传凭证

    NSString *uploadToken = [[QiniuToken sharedQiniuToken] uploadToken]

不推荐在生产环境的代码中直接填写 accesskey 和 secretKey 来使用。

QiniuFile

初始化要上传的七牛文件,图片,音频都可以。

以图片为例「NSData 方式」

    QiniuFile *file = [[QiniuFile alloc] initWithFileData:UIImageJPEGRepresentation(your_image, 1.0f)];

或者一段音频「路径方式」

    NSString *path = [NSString stringWithFormat:@"%@/%@",[NSBundle mainBundle].resourcePath,@"your_mp3"];
    QiniuFile *file = [[QiniuFile alloc] initWithPath:path];

或者 ALAsset

    QiniuFile *file = [[QiniuFile alloc] initWithAsset: your_asset]];

QiniuUploader

添加文件

    uploader.files = @[file, file, file];

这里的 QinniuFile 可以部分是图片,部分是视频、音频,不会对上传有任何影响。

设置并发上限

    [[QiniuUploader sharedUploader] setMaxConcurrentNumber:3];

建议不要设置过大,因为 iOS 的连接数是有限的。

开始上传

上面乱七八糟的设置完了后,就调用这个开始上传。

    [uploader startUpload:uploadToken uploadOneFileSucceededHandler:^(NSInteger index, NSDictionary * _Nonnull info) {
            NSLog(@"index: %ld info: %@",(long)index, info);
        } uploadOneFileFailedHandler:^(NSInteger index, NSError * _Nullable error) {
            NSLog(@"error: %@", error);
        } uploadOneFileProgressHandler:^(NSInteger index, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
             NSLog(@"index:%ld percent:%f",(long)index, totalBytesSent * 1.0 / totalBytesExpectedToSend);
        } uploadAllFilesComplete:^{
            NSLog(@"complete");
        }];

再次提醒,不要在 App 内直接写入 key。

取消全部上传任务

当你希望取消掉所有上传任务时

    [uploader cancelAllUploadTask]

最后

如果还有不清楚的地方, 可以看看 QiniuUploadDemo,里面什么都有。。。

如果你有希望加入的特性,可以在 issue 在留言。 最后无耻的求个star...

Thanks

Thanks for @pavelosipov

POSInputStreamLibrary 帮我节省了很多时间去做用文件流形式读取 ALAsset 的工作

更新记录

CHANGELOG.md

qiniu_upload's People

Contributors

anysome avatar huhuanming avatar isaced avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.