繁体   English   中英

通过服务模块将文件从Android上传到Drupal

[英]Upload a file from Android to Drupal via Services Module

我试图将图像从Android设备上传到Drupal网站

我在Drupal端将Service模块与方法file.create一起使用。

问题是下载后文件已损坏。

文件较小。

filemime设置具有n效果。

Javaside:

public Map saveFile(String localFilePath, String serverpath) throws XmlRpcException, IOException{


        HashMap<String, Object> account = new HashMap<String, Object>();

    File localFile = new File(localFilePath);

    Log.w("XMLRPC", "FILENAME "+localFile.getName() + " original "+localFile.length());



        String fileAsString = readFile(localFilePath);

        // Sending side
        byte[] data =  fileAsString.getBytes("UTF-8");
        byte[] base64 =  Base64.encode(data,Base64.URL_SAFE);

        account.put("file", base64);
        account.put("filename", localFile.getName());
        account.put("filepath", serverpath +"/"+ localFile.getName());
       // account.put("filemime", "application/x-compressed");
        account.put("filesize", Integer.parseInt(localFile.length()+""));//String.valueOf(localFile.length()));

        Vector<Object> params = new Vector<Object>();
        params.add(account);


        return (Map) xmlRpcClient.execute(METHOD_FILE_CREATE, params);
    }

好吧,如果您未在Drupal网站上使用本机android应用程序,则无需任何其他“界面”即可上传文件! 它应该像从桌面上载文件一样工作!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM