85477

Uploading image to server with ASIFormDataRequest

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

Recommend

  • Uploading images to a server using an iPhone
  • Apollo-React-GraphQL Mutation
  • execvp in C not going through ar
  • Is there a version of GNU indent which supports Objective C?
  • Not all data coming back from mysql query
  • angular 2 translation json observable does not work
  • Download images in order with AFNetworking
  • ASIHTTPRequest login page
  • How to create pre-signed URL in Objective C for S3 without SDK?
  • GeckoFX WebBrowser page height and width
  • Random number between forked processes is the same
  • How to limit the number of actors of a particular type?
  • How to add a dataset toggle to Chart.js?
  • Leaflet separated div element interaction
  • Switching role between fork and parent
  • Substitute a package in NPM/Node
  • How do I printf() after a call to execlp() in a child process?
  • finding the download size of a URL (Content-Length)
  • Why can I not read from stdin in this forked process?
  • How do you increment a count while using the sleep function?
  • Luabridge binding overloaded operators
  • Upload file onto Server from the IPhone using ASIHTTPRequest
  • Error getting audio input device sample rate: '!obj'
  • Using Node cluster module with SailsJs: EADDRINUSE
  • Associate git repo with existing fork network
  • Access user's phone number on iOS 7
  • Exchange data b/w iOS devices using Bluetooth 4.0
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Updating server-side rendering client-side
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • How to pass list parameters for each object using Spring MVC?
  • Circular dependency while pushing http interceptor
  • AngularJs get employee from factory
  • Free memory of cv::Mat loaded using FileStorage API
  • How to set the response of a form post action to a iframe source?
  • Memory offsets in inline assembly
  • Change div Background jquery
  • Turn off referential integrity in Derby? is it possible?
  • sending mail using smtp is too slow
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize