How to upload an audio file to Parse.com - Android -


i have path of file want upload parse.com.

for example, 1 of file paths is: "/storage/emulated/0/app100/2015-06-04_00:45:16_recordsound.3gp"

now, want upload parse.com. solution how it?

i've tried write method this, it's not working:

private parseobject uploadaudiotoparse(file audiofile, parseobject po, string columnname){      if(audiofile != null){         log.d("eb", "audiofile 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 parsefile         parsefile file = new parsefile(audiofile.getname() , audiobytes);         // upload file parse cloud         file.saveinbackground();         po.put(columnname, file);     }     return po; } 

thanks!

try following:

private parseobject uploadaudiotoparse(file audiofile, parseobject po, string columnname){  if(audiofile != null){     log.d("eb", "audiofile 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 parsefile     parsefile file = new parsefile(audiofile.getname() , audiobytes);     po.put(columnname, file);      // upload file parse cloud     file.saveinbackground();     po.saveinbackground(); } return po; 

}

put object in parseobject first, save file. also, added saving parseobject (po.saveinbackground()). since modified po, have save well. maybe did outside method, code linked didn't show this.

also, maybe try doing in asynctask , calling save() instead, in order make sure each step works (if 1 save or goes wrong, cancel task), or use savecallbackk provided follows: parseobject.saveinbackground( savecallback callback); , in done method call save po object once parsefile saves.

note: there limit parsefile size of 10mb, if audio file larger this, there issue.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -