我目前正在处理文件处理应用程序,我已经使用 AFNetworking 完成了图像上传,并从相机和图库中进行了多部分选择。 但我的问题是如何从设备 [iPhone] 中选择 pdf 文件? 如果您能给我一些答案,我将不胜感激。感谢高级。
这是我的图片上传代码..
AFHTTPRequestOperationManager *man = [[AFHTTPRequestOperationManager alloc]init];
man.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
int i=0;
[self dispLoaderOnView:self.view loaderText:@"Loading.."];
for(i=0 ; i< selectedImages.count; i++)
{
NSData *imageData = UIImagePNGRepresentation([selectedImages objectAtIndex:i]);
AFHTTPRequestOperation *op = [man POST:FileUpload parameters:@{
@"queryid":@"37",
@"txtFilesQuery[]":imageData,
@"selFileType[]":self.textFieldChooseFile.text,
}
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageData name:@"txtFilesQuery[]" fileName:[fileNamearray objectAtIndex:i] mimeType:@"image/png"];
}
success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"Success: %@ ***** %@", operation.description, operation.responseString);
if(i==selectedImages.count-1)
{
[self hideHUDLoader];
}
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"File Uploaded" message:@"Suucessfully.." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
} failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error: %@ ***** %@", operation.responseString, error);
}];
[op start];
}
最佳答案
NSData *imageData = UIImagePNGRepresentation([selectedImages objectAtIndex:i]);
用以下行替换此代码
NSData *myData = [NSData dataWithContentsOfFile:[selectedImages objectAtIndex:i]];
和
[formData appendPartWithFileData:imageData name:@"txtFilesQuery[]"fileName:[fileNamearray objectAtIndex:i] mimeType:@"image/png"];
按照以下代码替换此代码
[formData appendPartWithFileData:imageData name:@"txtFilesQuery[]"fileName:[fileNamearray objectAtIndex:i] mimeType:@"application/pdf"];
可能这对你有帮助......!!!!
如果对你有帮助,请告诉我。
关于ios - 从 iphone 上传 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30722876/