i want upload image webservice, when upload name of image saving, not image.
please find code , images reference.
- (void) imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { [self dismissmodalviewcontrolleranimated:yes]; nsdata *image = uiimagejpegrepresentation([info objectforkey:uiimagepickercontrolleroriginalimage], 0.1); nsmutablestring *urlstring = [[nsmutablestring alloc] initwithformat:@"name=thefile&&filename=recording"]; [urlstring appendformat:@"%@", image]; nsdata *postdata = [urlstring datausingencoding:nsasciistringencoding allowlossyconversion:yes]; nsstring *postlength = [nsstring stringwithformat:@"%d", [postdata length]]; nsstring *baseurl = @"http://192.168.2.34/service1.svc/upload/filename.png"; nsurl *url = [nsurl urlwithstring:baseurl]; nsmutableurlrequest *urlrequest = [nsmutableurlrequest requestwithurl:url]; [urlrequest sethttpmethod: @"post"]; [urlrequest setvalue:postlength forhttpheaderfield:@"content-length"]; [urlrequest setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; [urlrequest sethttpbody:postdata]; nsurlconnection *connection = [nsurlconnection connectionwithrequest:urlrequest delegate:self]; [connection start]; nslog(@"started!"); }
after uploading image , name of image appears below:
but when open image show nil.
i not sure going wrong..kindly me.
thanks in advance.
these lines wrong:
nsdata *image = uiimagejpegrepresentation([info objectforkey:uiimagepickercontrolleroriginalimage], 0.1); nsmutablestring *urlstring = [[nsmutablestring alloc] initwithformat:@"name=thefile&&filename=recording"]; [urlstring appendformat:@"%@", image]; nsdata *postdata = [urlstring datausingencoding:nsasciistringencoding allowlossyconversion:yes]; ... [urlrequest setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; [urlrequest sethttpbody:postdata];
replace with:
nsdata *image = uiimagejpegrepresentation([info objectforkey:uiimagepickercontrolleroriginalimage], 0.1); ... [urlrequest sethttpbody:image];
also should change 0.1 0.8 or something, or else quality terrible.
you need make sure server correctly reading data. depends using server side... in php how it:
$data = file_get_contents('php://input'); file_put_contents($data, 'filename.jpg');
Comments
Post a Comment