ios - Sending Images and data to PHP server-side -
it,s first time trying send images & data php server app, , quite confused what's best way achieve this.
in research, came across afnetworking library , this base64 library (which take suggestion in one), don't know if can achieve want or how implement it.
what want send data & images have relationship.
lets user
has upload user details + picture
, house details + picture
json
{ "userdetails": { "name":"jon", "surname":"smith", "phone":"123412", "userpic":"base64pic" }, "house": { "address":"123 asd", "postcode":"w2 e23", "housepic":"base64pic" } }
of course json
have include security validations.
my problem comes when avoid using base64
encoding given 33% size increase , don't know how send same information php.
i confused when trying send images & data have relationship , should stored taking relationship account in server.
basically looking way send same information not base64 encoded images
keeping relationship in data , trying send fewer request possible. possible? if how?
look @ example instance, eveything pretty self explanatory ask me if have questions
-(void) poststuff{ afhttpclient *httpclient = [[afhttpclient alloc] initwithbaseurl:[nsurl urlwithstring:@"https://www.yourdomain.com/"]]; nsdictionary *parameter = @{@"body"@"anything want say!"}; nsmutableurlrequest *request = [httpclient multipartformrequestwithmethod:@"post" path:@"api/v1/posts/newpost/" parameters:parameter constructingbodywithblock: ^(id <afmultipartformdata>formdata) { [formdata appendpartwithfiledata:imagedata name:@"image" filename:@"image.png" mimetype:@"image/png"]; }]; afhttprequestoperation *operation = [[afhttprequestoperation alloc] initwithrequest:request]; [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id responseobject) { nslog(@"done!!!"); } failure:^(afhttprequestoperation *operation, nserror *error) { nslog(@"error: %@", error); }]; [httpclient enqueuehttprequestoperation:operation]; }
Comments
Post a Comment