通过下面的代码上传PowerPoint时,我收到了成功的响应。它确实上传但文件已损坏。当通过PowerPoint打开服务器上的损坏文件时,我收到以下消息:通过AFNetworking上传PowerPoint得到损坏
“PowerPoint发现文件名.pptx中的内容存在问题.PowerPoint可以尝试修复该演示文稿。”
- (void)updateDocument:(NSString *) path parameters:(FileUploadParameters*)para success:(void (^)(void))success failure:(void (^)(NSError *error))failure
{
_postData = nil;
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:[ConfigurationUtil objectForKey:@"baseURL"]]];
_postData = [NSMutableData dataWithContentsOfFile:[path stringByStandardizingPath]];
_postData = [NSMutableData dataWithContentsOfFile:[path stringByStandardizingPath] options:NSDataReadingMapped error:nil];
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:HTTP_METHOD_POST
path:[self getQueryString:path parameter:para]
parameters:nil
constructingBodyWithBlock: ^(id <AFMultipartFormData>formData)
{
[formData appendPartWithFileData:_postData
name:[[path lastPathComponent] stringByDeletingPathExtension]
fileName:[[path lastPathComponent] stringByDeletingPathExtension] mimeType:@"application/powerpoint"];
}];
[request addValue:[NSString stringWithFormat:@"WRAP access_token=%@",[Tenant loadSharedTenantInstance].authToken] forHTTPHeaderField:@"Authorization"];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
if (success)
success();
}
failure:^(AFHTTPRequestOperation* operation, NSError* error)
{
if (failure)
failure(error);
}
];
[operation start];
}
这些文件究竟有什么不同?他们有不同的大小或一些字节被更改?当试图找到一个错误时,不要只看代码。 – Sulthan
您的成功或失败块被叫?我想知道数据是否没有完成发送,因为操作在方法结束时超出了范围。我一直遵循单身HTTP客户端的推荐模式,并将操作添加到其操作队列中。 –
这些文件看起来不一样,它们的大小相同。他们只是被标记为腐败。 PowerPoint中的修复按钮修复文件,但我需要该文件不被视为损坏。使用相同的代码可以上传没有损坏但不包含微软文档(即Excel,Word,PowerPoint)的PDF。成功块被调用。我得到了成功的回应。 – rosieBCPD1