标签<request>中缺少属性'filename'由名称空间'urn:xmpp:http:upload:0'限定

时间:2018-08-15 10:08:38

标签: android ejabberd smack

我正在尝试使用 ejabberd-18.06 SMACK-4.2.0 作为Android客户端在应用程序之间传输文件。

mod_http_upload 在ejabberd中配置,并使用SMACK中的 HttpFileUploadManager

当我尝试上传文件时,它没有上传。 从受阻的日志中获取以下错误:

  

标记中缺少名称空间“ urn:xmpp:http:upload:0”的属性“文件名”

但是您可以从ejabbered的详细调试日志中看到文件名

#iq{id = <<"1TNIF-33">>,type = get,lang = <<"en">>,
    from =
        #jid{
            user = <<"mamun">>,server = <<"localhost">>,
            resource = <<"130055862109590748621314">>,luser = <<"mamun">>,
            lserver = <<"localhost">>,
            lresource = <<"130055862109590748621314">>},
    to =
        #jid{
            user = <<>>,server = <<"upload.localhost">>,resource = <<>>,
            luser = <<>>,lserver = <<"upload.localhost">>,lresource = <<>>},
    sub_els =
        [#xmlel{
             name = <<"request">>,
             attrs = [{<<"xmlns">>,<<"urn:xmpp:http:upload:0">>}],
             children =
                 [#xmlel{
                      name = <<"filename">>,attrs = [],
                      children = [{xmlcdata,<<"img.jpg">>}]},
                  #xmlel{
                      name = <<"size">>,attrs = [],
                      children = [{xmlcdata,<<"19691">>}]},
                  #xmlel{
                      name = <<"content-type">>,attrs = [],
                      children =
                          [{xmlcdata,<<"application/octet-stream">>}]}]}],
    meta = #{ip => {192,168,1,5}}}
2018-08-15 21:52:17.204 [debug] <0.495.0>@ejabberd_router:do_route:352 route:
#iq{id = <<"1TNIF-33">>,type = error,lang = <<"en">>,
    from =
        #jid{
            user = <<>>,server = <<"upload.localhost">>,resource = <<>>,
            luser = <<>>,lserver = <<"upload.localhost">>,lresource = <<>>},
    to =
        #jid{
            user = <<"mamun">>,server = <<"localhost">>,
            resource = <<"130055862109590748621314">>,luser = <<"mamun">>,
            lserver = <<"localhost">>,
            lresource = <<"130055862109590748621314">>},
    sub_els =
        [#xmlel{
             name = <<"request">>,
             attrs = [{<<"xmlns">>,<<"urn:xmpp:http:upload:0">>}],
             children =
                 [#xmlel{
                      name = <<"filename">>,attrs = [],
                      children = [{xmlcdata,<<"img.jpg">>}]},
                  #xmlel{
                      name = <<"size">>,attrs = [],
                      children = [{xmlcdata,<<"19691">>}]},
                  #xmlel{
                      name = <<"content-type">>,attrs = [],
                      children =
                          [{xmlcdata,<<"application/octet-stream">>}]}]},
         #stanza_error{
             type = modify,code = 400,by = <<>>,reason = 'bad-request',
             text =
                 [#text{
                      lang = <<"en">>,
                      data =
                          <<"Missing attribute 'filename' in tag <request/> qualified by namespace 'urn:xmpp:http:upload:0'">>}],
             sub_els = []}],
    meta = #{ip => {192,168,1,5}}}

ejabberd配置:

mod_http_fileserver:
    docroot: "C:/ProgramData/ejabberd/upload"
    accesslog: "C:\\Program Files\\ejabberd-18.06\\logs\\access.log"

mod_http_upload:
   docroot: "C:/ProgramData/ejabberd/upload"
   put_url: "http://@HOST@:5443"
   custom_headers: 
     "Access-Control-Allow-Origin": "*"
     "Access-Control-Allow-Methods": "GET, POST, PUT, OPTIONS"
     "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept"
mod_http_upload_quota:
   max_days: 30
......
-
 port: 5280
 ip: "0.0.0.0"
 ##ip: "::"
 module: ejabberd_http
 request_handlers:
   "/ws": ejabberd_http_ws
   "/bosh": mod_bosh
   "/oauth": ejabberd_oauth
   "/api": mod_http_api
   "/pub/archive": mod_http_fileserver
 web_admin: true
 captcha: false
-
 port: 5443
 ip: "0.0.0.0"
 module: ejabberd_http
 tls: true
 request_handlers:
   "": mod_http_upload

SMACK代码:

HttpFileUploadManager httpFileUploadManager=
  HttpFileUploadManager.getInstanceFor(activity.getXmppConnectionManager()
 .getConnection());
File file = new File("/mnt/sdcard/img.jpg");
try {          
    Log.i("UPLOAD_SERVICE", 
      httpFileUploadManager.isUploadServiceDiscovered()+"");
    Log.i("FILE_UPLOAD",httpFileUploadManager.uploadFile( file);
  } catch (InterruptedException e) {
        e.printStackTrace();
  } catch (XMPPException.XMPPErrorException e) {
        e.printStackTrace();
  } catch (SmackException e) {
        e.printStackTrace();
  } catch (IOException e) {
        e.printStackTrace();
  }

0 个答案:

没有答案