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})