【问题标题】:Posting File data to a server? [closed]将文件数据发布到服务器? [关闭]
【发布时间】:2017-07-27 13:18:52
【问题描述】:

如何将这种格式的数据发送到服务器?

【问题讨论】:

    标签: android image http postman posting


    【解决方案1】:

    只需将其编码为 Base64。

    试试这个,

        private static String encodeFileToBase64Binary(File file) {
        String encodedfile = null;
        try {
            FileInputStream fileInputStreamReader = new FileInputStream(file);
            byte[] bytes = new byte[(int) file.length()];
            fileInputStreamReader.read(bytes);
            encodedfile = Base64.encodeToString(bytes, 1);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
        return encodedfile;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-11
      • 1970-01-01
      相关资源
      最近更新 更多