将文件数据发布到服务器?

时间:2017-03-07 10:59:35

标签: android image http postman posting

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

enter image description here

1 个答案:

答案 0 :(得分: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;
}