
Question:
Hi build a service for my iPhone app and need to have function that get image from the user: Until now i used to get only text with this method:
string input = null;
using (StreamReader sr = new StreamReader(Request.InputStream))
{
input = sr.ReadToEnd();
}
How should i get the image from the post?
This is how i send the image from the iphone app:
imageRequest = [ASIFormDataRequest requestWithURL:url];
[imageRequest addData:imageData withFileName:@"someFileName.jpeg" andContentType:@"image/jpeg" forKey:@"uploadedImage"];
[imageRequest setDelegate:self];
[imageRequest setRequestMethod:@"POST"];
[imageRequest startAsynchronous];
Answer1:You cannot upload image by adding image with name. First convert UIImage object into Base64Encoding string and then send that string to server.
Download supporting files from the link <a href="http://iphonesdksnippets.com/?tag=/uiimage" rel="nofollow">enter link description here</a>
and the use these methods
- (NSString*) stringFromImage:(UIImage*)image
{
if(image){
NSData *dataObj = UIImagePNGRepresentation(image);
return [dataObj base64Encoding];
} else {
return @"";
}
}
- (UIImage*) imageFromString:(NSString*)imageString
{
NSData* imageData =[NSData dataWithBase64EncodedString:imageString];
return [UIImage imageWithData: imageData];
}
Also check this link for Image to string and string to image in Base64 <a href="http://iphonesdksnippets.com/post/2010/03/14/Convert-image-tofrom-text-%28Base64%29.aspx" rel="nofollow">image conversion</a>
it helps u