Swift Firebase Get Image From Storage And Show In JSQMessage Controller

I want to get a saved Image in Firebase Storage.

I have the url saved in an string value in the Firebase database:

mediaUrl = url!.absoluteString

Now I want to get this image.

I observe the messages.

func observeMessages() {
    let query = Constants.refs.databaseChats.child(chatId).queryLimited(toLast: 50)

    _ = query.observe(.childAdded, with: { [weak self] snapshot in

        if  let data        = snapshot.value as? [String: String],
            let id          = data["sender_id"],
            let name        = data["name"],
            let timestamp   = data["timestamp"],
            let media       = data["media"],
            let text        = data["text"]?.encode(),
            if media == "text" {
                if let message = JSQMessage(senderId: id, senderDisplayName: name, date: self! timestamp), text: text) {
            else if media == "image" {
                let storageRef = text)
                storageRef.getData(maxSize: 1 * 1024 * 1024) { (data, error) -> Void in
                    if data != nil {
                        let image = UIImage(data: data!)
                        if let imageMessage = JSQMessage(senderId: id, senderDisplayName: name, date: self! timestamp), media: image as! JSQMessageMediaData) {
                            print("image message")


If the media is an image, I want to create an image bubble, and when text a normal text bubble. But I get no Image in the JSQMEssageViewController. What went wrong? Can someone help me there?

I get the url in console:

And after that I get the following at console:

2019-06-03 21:28:21.092580+0200 EMMessenger[38502:554129] [] nw_proxy_resolver_create_parsed_array PAC evaluation error: NSURLErrorDomain: -1003




Actually you don't need to call getData function for this case. As you're using tableView so I would recommend to use SDWebImage library to load the images on cells asynchronously. Once you have the imageURL just call below method

yourImageView.sd_setImage(with: URL(string: ""), placeholderImage: UIImage(named: "placeholder.png"))

Rest the library will do for you.