我正在尝试将DOCX文件存储到Parse云然后检索它,我遇到了一个问题,当我使用SDK PFile类下载文件或在两种情况下都使用URL时,文件数据会附加一些页眉和页脚,我想知道如何避免它,以便在将数据保存到文件后我可以用MS Office实际打开它。 标题如下
------------------------------d6ce5d079979
Content-Disposition: form-data; name="test.docx"; filename="test.docx"
Content-Type: application/octet-stream
如何从文件数据中删除上述内容? 我尝试使用AFNetworking下载任务下载文件以及PFile,两种情况下都存在于文件数据中。
PFQuery *query = [PFQuery queryWithClassName:@"DocFiles"];
[query getObjectInBackgroundWithId:@"juoEvcZG9W" block:^(PFObject *docs, NSError *error) {
// Do something with the returned PFObject in the gameScore variable.
PFFile *applicantResume = docs[@"docFile"];
[applicantResume getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
// NSLog(@"%@",data);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"test.docx"];
NSLog(appFile);
[data writeToFile:appFile atomically:YES];
strPath = appFile;
QLPreviewController *previewController=[[QLPreviewController alloc]init];
previewController.delegate=self;
previewController.dataSource=self;
[self presentModalViewController:previewController animated:YES];
[previewController.navigationItem setRightBarButtonItem:nil];
}];
}];
我用来上传的代码如下
$info = pathinfo($_FILES['userFile']['name']);
$ext = $info['extension']; // get the extension of the file
$newname = $_FILES['userFile']['name'];
$target = $newname;
move_uploaded_file( $_FILES['userFile']['tmp_name'], $target);
//error_reporting(-1);
ini_set('display_errors', true);
$handle = curl_init();
$url = "https://api.parse.com/1/files/".$newname;
$headers = array (
"X-Parse-Application-Id: ************",
"X-Parse-REST-API-Key: *************",
"Content-Type:application/vnd.openxmlformats-officedocument.wordprocessingml.document"
//"Content-Type:text/plain"
);
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_POST, true);
$data = array($newname => "@".$newname);
curl_setopt ($handle, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($handle);
最后还尝试通过创建下载任务使用AFNetworking使用URL下载文件,但问题仍然存在。