QNUploadOption.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // QNUploadOption.m
  3. // QiniuSDK
  4. //
  5. // Created by bailong on 14/10/4.
  6. // Copyright (c) 2014年 Qiniu. All rights reserved.
  7. //
  8. #import "QNUploadOption+Private.h"
  9. #import "QNUploadManager.h"
  10. static NSString *mime(NSString *mimeType) {
  11. if (mimeType == nil || [mimeType isEqualToString:@""]) {
  12. return @"application/octet-stream";
  13. }
  14. return mimeType;
  15. }
  16. @implementation QNUploadOption
  17. + (NSDictionary *)filteParam:(NSDictionary *)params {
  18. NSMutableDictionary *ret = [NSMutableDictionary dictionary];
  19. if (params == nil) {
  20. return ret;
  21. }
  22. [params enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
  23. if ([key hasPrefix:@"x:"] && ![obj isEqualToString:@""]) {
  24. ret[key] = obj;
  25. }
  26. }];
  27. return ret;
  28. }
  29. - (instancetype)initWithProgessHandler:(QNUpProgressHandler)progress {
  30. return [self initWithMime:nil progressHandler:progress params:nil checkCrc:NO cancellationSignal:nil];
  31. }
  32. - (instancetype)initWithProgressHandler:(QNUpProgressHandler)progress {
  33. return [self initWithMime:nil progressHandler:progress params:nil checkCrc:NO cancellationSignal:nil];
  34. }
  35. - (instancetype)initWithMime:(NSString *)mimeType
  36. progressHandler:(QNUpProgressHandler)progress
  37. params:(NSDictionary *)params
  38. checkCrc:(BOOL)check
  39. cancellationSignal:(QNUpCancellationSignal)cancel {
  40. if (self = [super init]) {
  41. _mimeType = mime(mimeType);
  42. _progressHandler = progress != nil ? progress : ^(NSString *key, float percent) {
  43. };
  44. _params = [QNUploadOption filteParam:params];
  45. _checkCrc = check;
  46. _cancellationSignal = cancel != nil ? cancel : ^BOOL() {
  47. return NO;
  48. };
  49. }
  50. return self;
  51. }
  52. + (instancetype)defaultOptions {
  53. return [[QNUploadOption alloc] initWithMime:nil progressHandler:nil params:nil checkCrc:NO cancellationSignal:nil];
  54. }
  55. @end