1

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

我在 Drupal 端使用了 Service 模块和方法 file.create。

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

文件更小。

filemime 设置有 n 效果。

爪哇:

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);
    }
4

1 回答 1

0

好吧,如果您的 Drupal 站点没有使用原生 android 应用程序,则不需要任何其他“接口”来上传文件!它应该像您从桌面上传文件一样工作!

于 2013-04-13T04:28:15.270 回答