我有一个文件路径,想要上传到Parse.com。
例如文件路径为: "/storage/emulated/0/app100/2015-06-04_00:45:16_RecordSound.3gp"
现在,我想将其上传到Parse.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;
}
谢谢!