-1

I want to upload follow Log Strings along with UIImage,

HOw can I achieve such objective????

I can see to send only image , but i want to send image along with text data using this ASIFormDataRequest, using POST request type.

  NSLog(@"data is here %@\n%@\n%@\n%@\n%@\n",deviceID, postID, name, message, picture);


    UIImage *image= [UIImage imageNamed:@"profile_avatar.png"];
    NSString *strURL = @"https://abc.abc.com/comments/create";

    //      ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]]; // Upload a file on disk
   // NSString *filename1=[NSString stringWithFormat:@"friendship.jpg"];
    UIImage *image1=image;
    NSData *imageData1=UIImageJPEGRepresentation(image1, 1.0);

    [request setData:imageData1 withFileName:@"filename" andContentType:@"image/png" forKey:@"avatar"];
    [request setRequestMethod:@"POST"];

    [request addRequestHeader:@"Authorization" value:[NSString stringWithFormat:@"Basic %@",[ASIHTTPRequest base64forData:[[NSString stringWithFormat:@"username123:pass123"] dataUsingEncoding:NSUTF8StringEncoding]]]];

    [request setValidatesSecureCertificate:NO];
    //[request appendPostData:body];
    [request setDelegate:self];
    [request setTimeOutSeconds:3.0];
    request.shouldAttemptPersistentConnection = NO;
    [request setDidFinishSelector:@selector(uploadRequestFinished:)];
    [request setDidFailSelector:@selector(uploadRequestFailed:)];
    [request startAsynchronous];

Thanks

Duaan
  • 609
  • 1
  • 13
  • 29

1 Answers1

3

There is one method available to send parameter as well

[request setPostValue:@"YourValue" forKey:@"YourKey"];
halfer
  • 19,824
  • 17
  • 99
  • 186
Janak Nirmal
  • 22,706
  • 18
  • 63
  • 99