我正在尝试使用mime类型的image / jpeg将图片上传到firebase,但出于某种原因,它们都上传为application / octet-stream。
见下我的代码片段:
let storageRef = Storage.storage().reference().child("ProfilePictures/\(image).jpg")
if let uploadData = UIImageJPEGRepresentation(self.pickedImage!, 0.5){
storageRef.putData(uploadData, metadata: nil, completion:{ (metadata, error) in })
我通过照片库中的选择器获得了图像
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let editedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
ImageButton.setBackgroundImage(editedImage, for: .normal)
ImageButton.setTitle("", for: .normal)
self.pickedImage = editedImage
}
dismiss(animated: true, completion: nil)
}
答案 0 :(得分:4)
您必须设置相同的元数据。
试试吧。
metadata = {contentType:' image / jpeg'};