从iphone上传pdf文件

时间:2015-06-09 04:12:17

标签: 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];


    }

1 个答案:

答案 0 :(得分:1)

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”];

这可能对你有帮助....... !!!!!

让我知道它是否有用。