ASIHTTPRequestErrorDomain 代码=8。无法将文件从临时目录移动到文档

发布于 2024-12-06 22:24:37 字数 1017 浏览 1 评论 0原文

我使用 ASIHTTPReqeust 下载文件。一切都下载正常,但无法将文件从临时目录移动到文档。当我实现

-(void) request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data

请求失败并出现错误时。但文件已下载。

如果我删除此实现,一切都很好,并且文件将移至文档。 这是错误文本:

Error Domain=ASIHTTPRequestErrorDomain Code=8 "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'" 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'}

谁遇到过类似的问题?

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 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'" 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满地尘埃落定 2024-12-13 22:24:37

经常让人们感到困惑的是,您必须自己创建要下载的目录(ASIHTTPRequest 不会自动创建它)。

然而,鉴于您说它与实现 didReceiveData 有关,但事实并非如此。

如果您查看 ASIHTTPRequest.m,您会发现如果您在委托中实现“didReceiveData”,则会看到它设置“dataWillBeHandledExternally” - 这将阻止数据写入磁盘。您可以自己编写数据,也可以更改 ASIHTTPRequest.m 代码以添加一个标志以强制它也在内部处理数据。

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.

千鲤 2024-12-13 22:24:37

我遇到了同样的错误,但原因不同。我将发布我的问题 - 以防万一其他人也有类似的情况。

我试图在保存新图像之前删除旧图像。

NSString *mImgName = [managedObj valueForKey:@"aImgName"];

NSString * mFilePath = [[self applicationDocumentsDirectory] 
                stringByAppendingPathComponent:mImgName];

if ([mFileManager fileExistsAtPath:mFilePath]) 
{
    [mFileManager removeItemAtPath:mFilePath error:nil];
}

问题是 - 如果 mImgName 为零,mFileManager 将删除整个目录。

通过添加额外的检查 nil 或太短的 mImgName 值,它解决了问题。

希望它能对某人有所帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文