How to send document file, image, video and video in XMPPFrameWork using ejabberd?

192 views Asked by At

I try to send the document file, image, video and video in XMPPFrameWork using ejabberd. I try this code to send image to opponent user.

  func sendImage(_ data:Data){
    let outgoingFileTransfer = XMPPOutgoingFileTransfer(dispatchQueue: .main)
    outgoingFileTransfer.activate(stream)
    outgoingFileTransfer.addDelegate(self, delegateQueue: .main)
    let opponent = XMPPJID(string: modelController.delegate?.userID() ?? .empty)!
    let recipient = XMPPJID(user: opponent.user, domain: opponent.domain, resource: "foo")
    do{
      outgoingFileTransfer.recipientJID = recipient
      outgoingFileTransfer.outgoingData = data
      try outgoingFileTransfer.start()
      try outgoingFileTransfer.start()
      try outgoingFileTransfer.send(data, named: Date().toString(format: .localPhotoSave), toRecipient: recipient, description: "outgoingFileTransfer Description")
    }catch{
      print(error.localizedDescription)
    }
  }
}

But I got error like this

Transfer already in progress.
"xmppOutgoingFileTransfer didFailWithError" Optional(Error Domain=XMPPOutgoingFileTransferErrorDomain Code=503 "<service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></service-unavailable>, <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" lang="en">User session not found</text>" UserInfo={NSLocalizedDescription=<service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></service-unavailable>, <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" lang="en">User session not found</text>})
1

There are 1 answers

2
eyup cimen On

My prefer is 3. party solution. For example you can use Firebase database.

  1. You can upload in Firebase Storage
  2. Firebase will give you download url
  3. You can this url in any message attached and send to other user and etc.