5

I generated the pdf in my iphone app, now i want to send that pdf to server. for that i am converting to NSData and i am sending.

I searched in google and i find solution by using "POST" but it is working for images.

In the server it is uploading but the pdf is not opening it says the attachment has some error

In the following code i did this:

NSData *pdfdata = [[NSData alloc] initWithData:[self.pdfFilePath dataUsingEncoding:NSASCIIStringEncoding]];
ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MainUrl,@"updatefile.php"]]];
[request setDelegate:self];
        [request setPostValue:appDelegate.userId forKey:@"userid"];
         [request addData:pdfdata forKey:@"file"];
[request startSynchronous];

//self.pdfFilePath = /var/folders/a0/a01nF1oGGkebQxw7H0YsBU+++TI/-Tmp-/MyAccount.pdf;

Please guide me,

Thanks in advance.

Carl Veazey
  • 18,392
  • 8
  • 66
  • 81
Babul
  • 1,268
  • 2
  • 15
  • 42
  • 1
    Having all your friends and/or sockpuppet accounts upvote your questions is pretty obvious :) At least this question is a real question though. I'm a bit suspicious of encoding it that way but without understanding how your server works it's hard to say. So maybe explain a bit about the kinds of requests are succeeding with your server vs. the one you're constructing in your iOS app. – Carl Veazey Sep 04 '12 at 10:04

1 Answers1

1

Instead of this

[request addData:pdfdata forKey:@"file"];

use the below code

[request setFile:self.pdfFilePath forKey:@"file"];
qqx
  • 18,947
  • 4
  • 64
  • 68
Babul
  • 1,268
  • 2
  • 15
  • 42