It is loaded on the server, but the PDF file does not open, it says that the attachment has some error

I created a pdf file in my iphone application, now I want to send this file to the server. To do this, I convert to NSData and submit.

I searched on google and I found a solution using "POST", but it works for images.

It is loaded on the server, but the PDF file does not open, it says that there is some error in the application.

In the following code, I did the following:

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;

I ask you to,

Thanks in advance.

+5
source share
1 answer

Instead of this

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

use the code below

[request setFile:self.pdfFilePath forKey:@"file"];
+1
source

All Articles