0

I'm making this wallpaper app that lets users download the wallpaper to their local system. The problem I am having: when creating a request to download a specific wallpaper, the request states "An unknown error occurred, please check the server response." Here is the error code in more depth when printing the entire error to the console:

Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response." UserInfo={object=wallpapers/37.jpg, bucket=flowr---flower-wallpapers.appspot.com, NSLocalizedDescription=An unknown error occurred, please check the server response., ResponseErrorDomain=NSCocoaErrorDomain, NSFilePath=/local/images, NSUnderlyingError=0x600003fcd380 {Error Domain=NSPOSIXErrorDomain Code=30 "Read-only file system"}, ResponseErrorCode=642}

One thing I noticed is that the error states that there is a "Read-only file system." On iOS do I need to get permission from the user, or do I need to place the downloaded image in an accessible directory on the user's system?

Here is the original code for the database request:

let wallpaperRef = Globals.storageRef.storage.reference(withPath: Globals.FireStoreDirectories.wallsDirectory + passedImageName)

    let localURL = URL(string: "file:///local/images/" + passedImageName)!

    // Download to the local filesystem
    let downloadTask = wallpaperRef.write(toFile: localURL) { url, error in
      if let error = error {
          DispatchQueue.main.asyncAfter(deadline: .now() + 0.75) {
              showLoadingToast = false
          }
          print(error.localizedDescription)
          print(error)
      } else {
          print("Download locale: " + url!.description)
          DispatchQueue.main.asyncAfter(deadline: .now() + 0.75) {
              showLoadingToast = false
          }
      }
    }

The wallpaper and the directories are all correct, however, the database request fails because of a read only file system.

ToxicFlame427
  • 355
  • 2
  • 13
  • Use `FileManager` instead of `file:///` for iOS – lorem ipsum Sep 30 '22 at 15:23
  • Could I get an example on how I could use it? – ToxicFlame427 Sep 30 '22 at 17:04
  • 1
    There are plenty of links and tutorials on how to write to a file in iOS. The way you are trying right now is for macOS. – lorem ipsum Sep 30 '22 at 17:17
  • I'm a little rusty with swift and firebase, but something I think you could try is using the `getData` function from Firebase, and then saving that data directly to the fileManager instead of getting the URL and trying to save the URL to fileManager. Here is an example of me using this for a different problem: https://stackoverflow.com/questions/70222090/how-do-you-allow-very-large-files-to-have-time-to-upload-to-firebase-before-ios – Trev347 Oct 01 '22 at 06:11

0 Answers0