If you transfer to NSData without damaging the image quality, if the image is very large, if it is in the main thread, the memory will increase and the UI will be stuck. If it is in the sub-thread, the UI will not be stuck. But the memory will also be very large. How to solve it? (Note: The test picture, the transferred data.length is about 20M)
phpcn_u15822017-05-02 09:30:12
Unable to solve, converting to NSData is similar to a decompression operation and cannot reduce memory usage.
If you need to send it to the server, it is recommended to use the method shown in the picture below.
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];