Last active
September 7, 2016 05:08
-
-
Save roblav96/7202d62c8f707cee56973ddd5bab579c to your computer and use it in GitHub Desktop.
This file contains 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
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://example.com/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { | |
[formData appendPartWithFileURL:[NSURL fileURLWithPath:@"file://path/to/image.jpg"] name:@"file" fileName:@"filename.jpg" mimeType:@"image/jpeg" error:nil]; | |
} error:nil]; | |
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; | |
NSURLSessionUploadTask *uploadTask; | |
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 | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
//Update the progress view | |
[progressView setProgress:uploadProgress.fractionCompleted]; | |
}); | |
} | |
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { | |
if (error) { | |
NSLog(@"Error: %@", error); | |
} else { | |
NSLog(@"%@ %@", response, responseObject); | |
} | |
}]; | |
[uploadTask resume]; |
This file contains 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
declare class AFHTTPRequestSerializer extends NSObject implements AFURLRequestSerialization { | |
multipartFormRequestWithMethodURLStringParametersConstructingBodyWithBlockError(method: string, URLString: string, parameters: NSDictionary, block: (p1: AFMultipartFormData) => void): NSMutableURLRequest; | |
} | |
interface AFMultipartFormData { | |
appendPartWithFileURLNameFileNameMimeTypeError(fileURL: NSURL, name: string, fileName: string, mimeType: string): boolean; | |
} | |
declare var AFMultipartFormData: { | |
prototype: AFMultipartFormData; | |
}; |
This file contains 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
let request: NSMutableURLRequest = AFHTTPRequestSerializer.serializer().multipartFormRequestWithMethodURLStringParametersConstructingBodyWithBlockError( | |
'POST', | |
'http://192.168.0.3:5338/upload', | |
null, | |
function block(formData: AFMultipartFormData) { | |
global.tnsconsole.dump('formData', formData) | |
global.tnsconsole.dump('formData.description', formData.description) | |
global.tnsconsole.error('formData.appendPartWithFileURLNameFileNameMimeTypeError', formData.appendPartWithFileURLNameFileNameMimeTypeError) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it says
formData.appendPartWithFileURLNameFileNameMimeTypeError
is undefined 😢