当我尝试将照片从图库上传到真实设备iPhone SE上的Firebase存储时,我在日志Swift中出错:
无法发布文件的沙箱扩展名 file:///var/mobile/Media/DCIM/101APPLE/IMG_1237.JPG,errno = 1错误 上传:发生未知错误,请检查服务器 响应。
但是如果我从Swift模拟器中尝试-一切正常。
上传照片的代码:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
picker.dismiss(animated: true, completion:nil)
guard let uid = Auth.auth().currentUser?.uid else { return }
if #available(iOS 8.0, *), let referenceURL = info[UIImagePickerController.InfoKey.referenceURL] as? URL {
let assets = PHAsset.fetchAssets(withALAssetURLs: [referenceURL], options: nil)
let asset = assets.firstObject
asset?.requestContentEditingInput(with: nil, completionHandler: { [weak self] (contentEditingInput, info) in
let imageFile = contentEditingInput?.fullSizeImageURL
let flip = arc4random_uniform(9999)
var rand = String(flip)
let filePath = "myFiles/myFile"
guard let strongSelf = self else { return }
let imgPath = strongSelf.storageRef.child(filePath)
imgPath.putFile(from: imageFile!, metadata: nil) { (metadata, error) in
if let error = error {
let nsError = error as NSError
print("Error uploading: \(nsError.localizedDescription)")
return
}
imgPath.downloadURL { (url, error) in
guard let downloadURL = url
else {
print("error")
return
}
print(downloadURL)
strongSelf.sendMessage(withData: [Constants.MessageFields.imageURL: downloadURL.absoluteString])
}
}
})
请帮助我修复它。
答案 0 :(得分:0)
我认为您尚未添加该应用访问画廊的权限?。 如果已添加,请确保在显示“访问”对话框时单击“允许”。