ios - 从 iphone 上传 pdf 文件

标签 ios

我目前正在处理文件处理应用程序,我已经使用 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/

相关文章:

ios - objective-c : Accessing properties of an object instance that's in an array that's a property of an object

ios - 创建自定义 VoiceOver 转子以垂直导航 UICollectionView

objective-c - UIActionSheet 在横向模式下不旋转?

iphone - 如何将一种货币值(value)转换为另一种货币值(value)

ios - 向 VBO 提供数据

ios - 什么是 CoreDataGeneratedAccessors?

ios - 在 AppDelegate 中对初始 ViewController 使用强委托(delegate)

ios - 使用 post 快速 JSON 登录 REST 并获取响应示例

iphone - UITextView - 水平滚动?

ios - 类的实例未在 Swift 中打印其值