考虑下面的代码:ASIHTTPRequest setDownloadDestinationPath不写入文件
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://192.168.2.71:3000/ios_file?filename=complaint&folder=encounters&id=3"]];
NSString *mediaPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
mediaPath = [mediaPath stringByAppendingPathComponent:@"complaint.MOV"];
[request setDownloadDestinationPath:mediaPath];
[request startSynchronous];
NSLog(@"Got the file!");
NSURL *theURL = [NSURL URLWithString:mediaPath];
NSLog(@"Time to Play File!");
NSLog(@"Filename is %@", [theURL absoluteString]);
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[theURL absoluteString]];
if (fileExists) {
NSLog(@"THE FILE EXISTS ZOMG");
}
// Create file manager
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
// Point to Document directory
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
// Write out the contents of home directory to console
NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
返回如下:
2011-03-30 18:29:46.107 VideoCapture[158:707] Get recording from server
2011-03-30 18:29:46.976 VideoCapture[158:707] Got the file!
2011-03-30 18:29:46.978 VideoCapture[158:707] Time to Play File!
2011-03-30 18:29:46.980 VideoCapture[158:707] Filename is /var/mobile/Applications/AE4B3091-3726-4FAE-B861-C4AE3616E743/Documents/complaint.MOV
2011-03-30 18:29:46.986 VideoCapture[158:707] Documents directory: (null)
将有问题的URL给我发送QuickTime影片(我使用Ruby的send_data File.read(“#{file_path} .MOV”),:disposition =>'inline',:type =>“video/quicktime”)。
如您所见,目录中没有文件!帮帮我!
另外只是要注意,我试着用服务器的直接文件(http://192.168.2.71:3000/fake_recordings/encounters/2/complaint.MOV),而不需要一个控制器,这有相同的问题。即使我可以在两种情况下都使用我的网络浏览器正确打开文件。 – mattvv 2011-03-31 01:44:23
尝试添加失败回调并查看它是否被调用? – Nevin 2011-03-31 01:54:29
有效的点,我做到了,并得到这个: 2011-03-30 19:01:01.957 VideoCapture [246:707]错误:无法将文件从'/ private/var/mobile/Applications/AE4B3091-3726- 4FAE-B861-C4AE3616E743/tmp/6A81D988-74EF-4085-AB1F-8EFF11008736-246-0000000F08A0C88D'至'/var/mobile/Applications/AE4B3091-3726-4FAE-B861-C4AE3616E743/Documents/complaint.MOV' – mattvv 2011-03-31 02:01:27