我有一个文件的路径,我想上传到Parse.com。如何将音频文件上传到Parse.com - Android
例如,文件路径之一是: “/storage/emulated/0/app100/2015-06-04_00:45:16_RecordSound.3gp”
现在,我要上传到解析.COM。任何解决方案如何做到这一点?
我试图写一个方法这一点,但它不工作:
private ParseObject uploadAudioToParse(File audioFile, ParseObject po, String columnName){
if(audioFile != null){
Log.d("EB", "audioFile is not NULL: " + audioFile.toString());
ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedInputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(audioFile));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int read;
byte[] buff = new byte[1024];
try {
while ((read = in.read(buff)) > 0)
{
out.write(buff, 0, read);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
byte[] audioBytes = out.toByteArray();
// Create the ParseFile
ParseFile file = new ParseFile(audioFile.getName() , audioBytes);
// Upload the file into Parse Cloud
file.saveInBackground();
po.put(columnName, file);
}
return po;
}
谢谢!
有来自logcat的任何输出,或只是不上传到解析 –
它只是没有上传来解析。 –
回答下面,这应该是解决方案! –