0

I'm trying creating a iOS app where the user can upload pdf, images, docs etc...,

This is my code - it works just one time; when I try again I get the error shown down below.

I don't understand why - I'm new to iOS development

class DocumentViewController: UIViewController, UIDocumentPickerDelegate, UIDocumentBrowserViewControllerDelegate{
    let storage = Storage.storage()
    
    enum UploadFileType{
        case file
        case PDF
    }
    struct UploadFileData{
        var fileName: String
        var fileType: UploadFileType
        var fileData: NSData
    }
    
    var file: UploadFileData?
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    @IBAction func addDocumetPress(_ sender: UIButton) {
        let documentsPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypePDF), String(kUTTypeImage), String(kUTTypeVideo), String(kUTTypePlainText),String(kUTTypeItem),String(kUTTypeFolder)], in: .import)
        documentsPicker.delegate = self
        documentsPicker.allowsMultipleSelection = true
        present(documentsPicker, animated: true, completion: nil)
        
    }
    
    func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
        controller.dismiss(animated: true,completion: nil)
    }
    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        
        let files = storage.reference().child("Customer Name")
        
        files.child((urls.first?.deletingPathExtension().lastPathComponent)!).putFile(from: urls.first!,metadata: nil){
            (_, error) in
            if error != nil{
                print("Files didn't upload, \(String(describing: error))")
            }
            print("Success")
        }
    }

This is the error I get:

Files didn't upload, Optional(Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response." UserInfo={_kCFStreamErrorCodeKey=40, NSURLErrorFailingURLSessionTaskErrorKey=BackgroundUploadTask .<1>, bucket=rgtestiosapp.appspot.com, object=customer Name/Boundaries When to Say Yes, How to Say No to Take Control of Your Life ( PDFDrive ), _NSURLErrorRelatedURLSessionTaskErrorKey=( "BackgroundUploadTask .<1>", "LocalUploadTask .<1>" ), NSLocalizedDescription=An unknown error occurred, please check the server response., ResponseErrorDomain=NSPOSIXErrorDomain, _kCFStreamErrorDomainKey=1, NSErrorPeerAddressKey={length = 28, bytes = 0x1c1e01bb 00000000 2a001450 4001082b ... 0000200a 00000000 }, ResponseErrorCode=40})

7
  • Can you try removing deletingPathExtension? Commented Jun 30, 2022 at 15:26
  • I try it but no success, thanks anyway Commented Jun 30, 2022 at 18:41
  • It's the second day that I have been working to solve this problem, What I have found is I try the same project in another pc in Virtualmachine and it wokrs, but in my mac with M1 chip it's not working because my app doesn't show up in the privacy of the folder Settings>Privacy>File and Folder Commented Jul 1, 2022 at 14:01
  • There could be a number of issues causing that error. You're force unwrapping a lot of vars which could lead to crashes. Also, there's no troubleshooting indicated it the question... did you add a breakpoint and step through your code line by line, inspecting vars and code execution along the way until you spot something unexpected? Can you do that and tell us which line is providing unexpected results and what you were expecting? Commented Jul 1, 2022 at 22:37
  • I put a breakpoint and i follow each step when the breakpoint was at putFile he throw the error files.child((urls.first?.lastPathComponent)!).putFile(from: urls[0].absoluteURL,metadata: nil) Commented Jul 2, 2022 at 0:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.