Created
February 12, 2017 19:15
-
-
Save VincentSit/0df24a0955101a6efd14a727d6040ef6 to your computer and use it in GitHub Desktop.
Upload data to QiNiu(qiniu.com) Raw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSURLSessionUploadTask *)uploadData:(NSData *)data completionHandler:(HXFStringCompletionBlock)completionHandler { | |
NSParameterAssert(data); | |
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" | |
URLString:@"http://upload.qiniu.com" | |
parameters:@{@"token": self.uploadToken} | |
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { | |
[formData appendPartWithFileData:data name:@"file" fileName:@"?" mimeType:@"image/jpeg"]; | |
} error:nil]; | |
// @property (nonatomic, strong) AFURLSessionManager *sessionManager; | |
// _sessionManager = [[AFURLSessionManager alloc] init]; | |
NSURLSessionUploadTask *uploadTask = [self.sessionManager uploadTaskWithStreamedRequest:request | |
progress:nil | |
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { | |
}]; | |
[uploadTask resume]; | |
return uploadTask; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment