Skip to content

Instantly share code, notes, and snippets.

@VincentSit
Created February 12, 2017 19:15
Show Gist options
  • Save VincentSit/0df24a0955101a6efd14a727d6040ef6 to your computer and use it in GitHub Desktop.
Save VincentSit/0df24a0955101a6efd14a727d6040ef6 to your computer and use it in GitHub Desktop.
Upload data to QiNiu(qiniu.com) Raw
- (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