如何使用Swift上传PDF,DOC,TXT,图像在Firebase存储中的图像
我正在尝试创建一个iOS应用程序,用户可以在其中上传PDF,图像,文档等...
这是我的代码 - 它只能使用一次;当我再次尝试时,我会得到下面显示的错误。
我不明白为什么 - 我是iOS开发的新手,
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")
}
}
这是我遇到的错误:
文件没有上传,可选(错误域= firstRoveerRordomain代码= -13000“发生了一个未知的错误,请检查服务器响应。 ,bucket = rgtestiosapp.appspot.com,object =客户名称/边界何时说是,如何说否以控制您的生活(pdfdrive),_nsurlorrorrerreRRERRERRERRERERERERLSESSIONTASKERROREKEY =(( “ BackgroundUploadTask。&lt; 1&gt;”, “ localuploadtask。&lt; 1&gt;” ),nslocalizedDescription =发生未知的错误,请检查服务器响应= 40})< /p>
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})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论