Search code examples
javaandroidasmack

How to send file in Android with Asmack+Openfire?


could you please send me the code to send file using Asmack + openfire.
I tried, but I am getting error like error code="503" type="cancel.
Please, help me.


Solution

  • You have to send a fully-qualified jabber ID as detination userID when you create the OutgoingFileTransfer it consists of a node, a domain, and a resource (user@domain/resource) as I said before in the comments, actually you are sending a2@aaa and is not correct.

    <iq id="SU8c1-17" to="a2@aaa" from="a1@aaa/Smack" type="set">
        <si xmlns="http://jabber.org/protocol/si" id="jsi_2427513438410796738" profile="http://jabber.org/protocol/si/profile/file-transfer">
            <file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="user.json" size="379">
                <desc>test_file</desc>
            </file>
            <feature xmlns="http://jabber.org/protocol/feature-neg">
                <x xmlns="jabber:x:data" type="form">
                    <field var="stream-method" type="list-multi">
                        <option>
                            <value>http://jabber.org/protocol/bytestreams</value>
                        </option>
                        <option>
                            <value>http://jabber.org/protocol/ibb</value>
                        </option>
                    </field>
                </x>
            </feature>
        </si>
    </iq>
    

    So, your sentTo variable shoulbe

    String sentTo = "user@domain/resource";
    
    OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(sentTo)