Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
- [dic setObject:@"uploadMedia" forKey:@"mode"];
- [dic setObject:@(ShareObj.loginUser.userId) forKey:@"userId"];
- [dic setObject:[self base64forData:mediaData] forKey:@"media"];
- {
- NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer]
- multipartFormRequestWithMethod:@"POST"
- URLString:@"http://www.myserver.com/webservice.php"
- parameters:dic
- constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
- {
- [formData appendPartWithFileURL:[NSURL fileURLWithPath:_mediaPath]
- name:@"file"
- fileName:_mediaName
- mimeType:@"image/jpeg"
- error:nil];
- }
- error:nil];
- AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
- AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
- [manager setResponseSerializer:responseSerializer];
- uploadTask = [manager
- uploadTaskWithStreamedRequest:request
- progress:^(NSProgress * _Nonnull uploadProgress) {
- // This is not called back on the main queue.
- // You are responsible for dispatching to the main queue for UI updates
- }
- completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
- if (error) {
- NSLog(@"Error: %@", error);
- } else {
- NSLog(@"%@ %@", response, responseObject);
- }
- }];
- [uploadTask resume];
- }
Add Comment
Please, Sign In to add comment