ASIHTTPRequestErrorDomain Code=8. Cannot move file from temp directory to docs
I download files with ASIHTTPReqeust. Everything downloads fine but it can't move file from temp directory to documents. When i implement
-(void) request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data
request fails with an error. But file is downloaded.
If i remove this implementation, everything is fine, and files are moving to docs. Here is Error text:
Error Domain=ASIHTTPRequestErrorDomain Code=8 "Failed to move fil开发者_运维百科e from '/var/folders/Qu/Qu0o0VcpEY4npJr2C1yPzE+++TI/-Tmp-/Skrillex feat. Nero - Wobbleland.mp3' to '/Users/Timur/Library/Application Support/iPhone Simulator/4.3/Applications/34389282-4013-4354-95D9-DF2847B4EE55/Documents/Audio/Skrillex feat. Nero - Wobbleland.mp3'" UserInfo=0x5949520 {NSUnderlyingError=0x59992a0 "The operation couldn’t be completed. (Cocoa error 4.)", NSLocalizedDescription=Failed to move file from '/var/folders/Qu/Qu0o0VcpEY4npJr2C1yPzE+++TI/-Tmp-/Skrillex feat. Nero - Wobbleland.mp3' to '/Users/Timur/Library/Application Support/iPhone Simulator/4.3/Applications/34389282-4013-4354-95D9-DF2847B4EE55/Documents/Audio/Skrillex feat. Nero - Wobbleland.mp3'}
Who had similar problem?
Something that often catches people out is that you have to create the directory that you're downloading into yourself (ASIHTTPRequest won't create it automatically).
However given you say it's related to the implementing didReceiveData it's not that.
If you look at ASIHTTPRequest.m, you'll see it sets 'dataWillBeHandledExternally' if you implement 'didReceiveData' in the delegate - this will be preventing the data being written to disk. You can either write the data yourself, or you could change the ASIHTTPRequest.m code to add a flag to force it to handle the data internally too.
I encountered same error, but the reason was different. I will post my problem - just in case anyone else has similar situation.
I was trying to delete old images, before saving new ones.
NSString *mImgName = [managedObj valueForKey:@"aImgName"];
NSString * mFilePath = [[self applicationDocumentsDirectory]
stringByAppendingPathComponent:mImgName];
if ([mFileManager fileExistsAtPath:mFilePath])
{
[mFileManager removeItemAtPath:mFilePath error:nil];
}
Problem was - in case mImgName is nil, mFileManager will delete whole directory.
By adding extra checking for nil or too short mImgName value, it solved problem.
Hopefully it will help someone!
精彩评论