我有一個文件的路徑,我想上傳到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的任何輸出,或只是不上傳到解析 –
它只是沒有上傳來解析。 –
回答下面,這應該是解決方案! –