-1
由于我使用的文件很大,我的函数返回一个超出限制的字符串。大文件到base64字符串数组
有没有办法创建一个返回字符串数组的函数,以便稍后我可以级联它们并重新创建该文件?
private String ConvertVideoToBase64()
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis;
try {
File inputFile = new File("/storage/emulated/0/Videos/out.mp4");
fis = new FileInputStream(inputFile);
byte[] buf = new byte[1024];
int n;
while (-1 != (n = fis.read(buf)))
baos.write(buf, 0, n);
byte[] videoBytes = baos.toByteArray();
fis.close();
return Base64.encodeToString(videoBytes, Base64.DEFAULT);
//imageString = videoString;
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
如何将文件写入1024字节的块?另外,假设我将文件写入1024字节块,我还需要将每个块转换为base-64并将它们添加到服务器端收集对吗? – 0014
编辑我的回答:) – MattD
+1为你的不错的答案:)是的我发布base64数据到一个Web服务,但我通过发送总字符串到一个电话一次。因此,如果可能的话,我宁愿使用参数(比如说mediaString [])。你推荐的就像是将数据同步到一个Web服务,我宁愿这样做后获得mediaString []。 – 0014