When using uploadTask(with:fromFile:) to perform an upload in the background, should the fileUrl be kept in the temp directory:
Or should it instead be the Caches directory?
I ask because I am starting to see this crashing stack:
Coming from:
And I suspect that the file is maybe being deleted while also being actively used by a background uploadTask?
The Apple File System basics docs say this about data in the temporary directory:
It says this about caches:
Code Block NSTemporaryDirectory()
Or should it instead be the Caches directory?
Code Block NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)
I ask because I am starting to see this crashing stack:
Code Block Fatal Exception: NSInvalidArgumentException Cannot read file at file:///private/var/mobile/Containers/Data/Application/XXXXXXXX-XXXX-XXXX-XXXX-CB39D5E080D9/tmp/org.alamofire.manager/multipart.form.data/XXXXXXXX-XXXX-XXXX-XXXX-28C54136FC0A
Coming from:
Code Block Request.swift - Line 583partial apply for closure #2 in UploadRequest.Uploadable.task(session:adapter:queue:) + 583
And I suspect that the file is maybe being deleted while also being actively used by a background uploadTask?
The Apple File System basics docs say this about data in the temporary directory:
[you] cannot rely on these files persisting after your app terminates
It says this about caches:
NOTE: though this crashing stack is coming from Alamofire, I am in the process of re-writing it from scratch using pure-native Apple APIs, so assume for the purposes of this question that Alamofire is not part of the stack. Where should I be writing temporary files for upload?Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file