Save image to firebase as image/jpeg using swift


Save image to firebase as image/jpeg using swift

I'm trying to upload pictures to firebase with a mime type of image/jpeg but for some reason they all upload as application/octet-stream.
Heres my code snippet:
let storageRef ="ProfilePictures/\(image).jpg")
        if let uploadData = UIImageJPEGRepresentation(self.pickedImage!, 0.5){
            storageRef.putData(uploadData, metadata: nil, completion:{ (metadata, error) in })

I got the image through a picker from the photo gallery
    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)


Solution 1:

You have to set the metadata for the same.

Try it.

metadata = { contentType: ‘image/jpeg’};