[IOS] Server use PHP when multiple picture upload afnetworking settings

Source: Internet
Author: User

When using PHP with a different server than the Java server

[FormData appendpartwithfiledata:uiimagejpegrepresentation (_pharray[i], 0.1f) name:@ "file[]" filename:[nsstring stringwithformat:@ "%@.png", FileName] mimetype:@ "Multipart/form-data"];

The name parameter cannot be set to @ "file" needs to be set to "file[]" otherwise the server will not resolve to the file array can only resolve the last picture

The specific code is as follows:

#pragmaMark-Send data-(void) postdata {nsmutabledictionary*infodic =[Nsmutabledictionary dictionary]; Nsdictionary* Para =[Nsdictionary dictionary]; Para= @{@"Info": infodic.jsonstring}; NSString* URL =@"filesupload.php"; Afhttpsessionmanager*manager =[Afhttpsessionmanager Manager]; Manager.responseserializer= [AfhttpresponseserializerNew]; [Manager post:[nsstring stringWithFormat:@"%@%@", Exile_base_api,url] Parameters:para constructingbodywithblock:^ (ID<AFMultipartFormData>_nonnull FormData) {        if(_pharray.count) { for(inti =0; i<_pharray.count; i++) {NSString*filename = [NSString stringWithFormat:@"%.f_%d", [[NSDate date]timeintervalsince1970],i]; [FormData appendpartwithfiledata:uiimagejpegrepresentation (_pharray[i],0.1f) Name:@"file[]"Filename:[nsstring stringWithFormat:@"%@.png", FileName] MimeType:@"Multipart/form-data"]; }}} Progress:nil success:^ (Nsurlsessiondatatask * _nonnull task,ID_nullable Responseobject) {Nsdictionary*dic =[nsjsonserialization jsonobjectwithdata:responseobject options:nsjsonreadingmutablecontainers Error:nil]; NSLog (@"Response ==>%@", DIC); } Failure:^ (Nsurlsessiondatatask * _nullable task, Nserror *_nonnull Error) {Exile_alert (nil, error.localizeddescription)}];}

[IOS] Server use PHP when multiple picture upload afnetworking settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.