1

I am trying to receive the url image and post the image into base64 format.

i am worked out this way but i didn't find any solution.

my .h file

@interface urlconnection : NSObject
{
    id delegate;
    NSMutableData *receivedData;
    NSURL *url;
    // NSData * imageData;
    IBOutlet NSImageView * myimages; 
        //and also trying UIImageView also atleast i didn't receive the image  
}

@property (nonatomic,retain) NSMutableData *receivedData;
@property (retain) id delegate;

- (void)post: (NSString *)urlString;

@end

my implementation file is

- (void)post: (NSString *)urlString {
        myimages.image = [NSImageView imageWithData:[NSData dataWithContentsOfURL:
            [NSURL URLWithString:@"http://www.iphonedevelopers.com/files/2010/03/iphone-sdk2.jpg" ]]];
        NSLog(@"image shown successfully");

        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:
            [NSURL URLWithString:@"http://www.iphonedevelopers.com/files/2010/03/iphone-sdk2.jpg"]];  

    [request setHTTPMethod:@"POST"];
    [request setValue:@"image/" 
        forHTTPHeaderField:@"Content-type"];
    [request setValue:[NSString stringWithFormat:@"%d", imageData length]] 
        forHTTPHeaderField:@"Content-length"];
    [request setHTTPBody:imageData];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];

please friends help me because i am new this concept

and please suggest the best tutorial for this concepts....

MrTJ
  • 13,064
  • 4
  • 41
  • 63
kumar
  • 453
  • 1
  • 5
  • 26
  • 2
    `myimages.image = [NSImageView imageWithData:[NSData dataWithContentsOfURL:...` should be `NSImage`, right? also, for base64 encoding see http://stackoverflow.com/questions/5999370/nsdata-to-base64 – Michał Zygar Apr 03 '12 at 09:49

3 Answers3

2

To post an image, you need a proper server webservice that is able to receive your image on server side..

Try this link that help you to upload your image from application

I think using asynchronous file downloading for image will be proper approach for downloading image since your code will freeze app until your image is downloaded.

You can try this link. There might be better downloader examples then this.

DivineDesert
  • 6,924
  • 1
  • 29
  • 61
1

myimages.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL

    URLWithString:@"http://www.iphonedevelopers.com/files/2010/03/iphone-sdk2.jpg" ]]];
1

To get the image from an URL:

  yourImageView.image= [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:stringContainningURL]]];
matthias krull
  • 4,389
  • 3
  • 34
  • 54
Anand
  • 1,129
  • 7
  • 29