Search code examples
iphoneobjective-casihttprequest

How to upload a complete image (not data in bytes) to a server in iphone?


I want to upload an image to server .I know to convert image ti NSData and then send it to server but is there any way to send complete image from your bundle to server without byte conversion? If there is a way i will be thankful if someone provide me details about this


Solution

  • NO you cannot send the image direct to the server because image url is not found. What you cando is convert yor image in data and then data in base 64 encoding string and send that string to the server You can do it like this:-

        NSData *imagedata=[NSData dataWithData:UIImagePNGRepresentation(*yourimagename*)];
        NSString *base64string=[imagedata base64EncodedString]; 
    

    Send image like this:-

        [request setPostValue:base64string forKey:@"image"];