Monday, December 11, 2023
HomeiOS Developmentios - Error "No such file or listing exists" whereas attempting to...

ios – Error “No such file or listing exists” whereas attempting to create listing and save pictures to file supervisor


I’m attempting to save lots of pictures domestically by saving them to the FileManager. By some means it’s not working and I do not know why.

helloid is the id of the occasion I’m attempting to retrieve pictures from.
First I get the picture after which I strive to reserve it domestically.

That is the code:


    /// This operate downloads all footage of a selected occasion
    /// - Parameter helloid: ID of the occasion
    func retrieveAllPictures(helloid: String) async {
        let db = Firestore.firestore()
        var comprises = false
        let outcome = strive? await db.assortment("occasions").doc(helloid).getDocument()
        
        if(outcome?.knowledge() != nil){
            allPictureIDs = (outcome?.knowledge()!["pictures"] as? [String])!
        }
        
        for i in allPictureIDs {
            if(i == helloid) {
                comprises = true
            }
        }
        if(allPictureIDs != nil){
        for pathOfIds in allPictureIDs {
            let storage = Storage.storage().reference()
            let fileRef = storage.little one(pathOfIds)
            
            do {
                let knowledge : Knowledge = strive await withCheckedThrowingContinuation  { continuation in
                    fileRef.getData(maxSize: 5000 * 1024) { knowledge, error in
                        if let error = error {
                            continuation.resume(throwing: error)
                        } else {
                            continuation.resume(returning: knowledge!)
                        }
                    }
                }
                let imageFinal = UIImage(knowledge: knowledge)!
                self.retrievedEventImages.append(imageFinal)
                
                let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
                let myCustomDirectory = documentsDirectory.appendingPathComponent("directory_(helloid)")
                
                //checking if listing already exists
                if !FileManager.default.fileExists(atPath: myCustomDirectory.path) {
                    do {
                        strive FileManager.default.createDirectory(at: myCustomDirectory, withIntermediateDirectories: true, attributes: nil)
                        let imageURL = myCustomDirectory.appendingPathComponent("(pathOfIds)")
                        if let imgData = imageFinal.jpegData(compressionQuality: 1.0){
                            do {
                                strive imgData.write(to: imageURL)
                            } catch {
                                print(error)
                            }
                        }
                    } catch {
                        print(error)
                    }
                } else {
                    let imageURL = myCustomDirectory.appendingPathComponent("(pathOfIds)")
                    //checking if file already exists in listing, if not add it to the listing
                    if !FileManager.default.fileExists(atPath: imageURL.path){
                        if let imgData = imageFinal.jpegData(compressionQuality: 1.0){
                            do {
                                strive imgData.write(to: imageURL)
                            } catch {
                                print(error)
                            }
                        }
                    }
                    
                }
                
            } catch {
                print(error)
            }
        }} else {
            self.retrievedEventImages.append(UIImage(systemName: "x.circle"))
        }
}

Once I run the code I get the error:

/Purposes/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Assets/RuntimeRoot/System/Library/CoreImage/PortraitFilters.cifilter.
Error Area=NSCocoaErrorDomain Code=260 "The file “xBFcVvTJbnmB5ZxY1E1y” couldn’t be opened as a result of there isn't any such file."

“xBFcVvTJbnmB5ZxY1E1y” is the identify of the listing

I additionally get the error

{NSFilePath=/Customers/Library/Developer/CoreSimulator/Units/E0F6567B-0C54-4F9D-A2C1-9CAAC27EBD65/knowledge/Containers/Knowledge/Software/ED505ADE-03F5-4953-8A0B-C0956FDD0612/Paperwork/directory_xBFcVvTJbnmB5ZxY1E1y/xBFcVvTJbnmB5ZxY1E1y/0.jpg, NSUnderlyingError=0x6000016f13b0 {Error Area=NSPOSIXErrorDomain Code=2 "No such file or listing"}}
Error Area=NSCocoaErrorDomain Code=4 "The file “1.jpg” doesn’t exist."

the file 1.jpg is a picture

When I attempt to run the code it skips the

if !FileManager.default.fileExists(atPath: myCustomDirectory.path)

and retains on operating at

 else {
                    let imageURL = myCustomDirectory.appendingPathComponent("(pathOfIds)")
                    //checking if file already exists in listing, if not add it to the listing
                    if !FileManager.default.fileExists(atPath: imageURL.path){
                        if let imgData = imageFinal.jpegData(compressionQuality: 1.0){
                            do {
                                strive imgData.write(to: imageURL)
                            } catch {
                                print(error)
                            }
                        }
                    }
              } 

then it goes into

if !FileManager.default.fileExists(atPath: imageURL.path)

and tries to

strive imgData.write(to: imageURL)

however fails and results in the catch block

I’m attempting to retrieve the photographs from Firebase Storage and save them to the file supervisor.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments