Home Support SMS API

Upload Audio File

Description: The user can upload an audio file via this API. For sending audio group call, the audio file ID can be used for launching a group call. It supports uploading of files of .mp3, .m4a or .wav format.

Request Parameters Description:

Parameters Description Required Type

fileName

File name with suffix, 5-32 characters. Repetition of names is not allowed.

Yes

String

file

File contents of base64 code (For base64 code conversion, please refer to the JAVA sample code at the very bottom of the program.)

Yes

String

Request URL:

                    
                      https://api.onbuka.com/v3/voice/fileUpload
                    
                  

Request Sample:

                    
                      RequestURL:
                        https://api.onbuka.com/v3/voice/fileUpload
                      RequestMethod:
                        POST
                      RequestHeaders:
                        Content-Type: application/json;charset=UTF-8
                        Sign: 05d7a50893e22a5c4bb3216ae3396c7c
                        Timestamp: 1630468800
                        Api-Key: bDqJFiq9
                      RequestBody:
                        {
                          "fileName": "c:tmptest.mp3",
                          "file": "File content encoded with base64"
                        }
                    
                  

Response Parameters Description:

Parameters Description Type

status

"0"means successful, others than 0 means failure, seeing Status code description.

String

reason

Failure reason description

String

data

Audio file ID

String

Response Sample:

                    
                      {
                        "status": "0",
                        "reason": "success",
                        "data": "1202202254d4c6372d6f341e999c7ecd0683ee464.mp3"
                      }
                    
                  

Sample code for Java-base64 code conversion:

                    
                        package com;
                        import cn.hutool.core.codec.Base64;
                        import java.io.File;
                        import java.io.FileInputStream;
                        import java.io.FileNotFoundException;
                        import java.io.IOException;
    
                        public class fileUpload {
                            public static void main(String[] args) {
                                File f = new File("c:tmptest.mp3");
                                System.out.println(file2Base64(f));
                            }
    
                            public static String file2Base64(File file) {
                                if (file == null) {
                                    return null;
                                }
                                String base64 = null;
                                FileInputStream fin = null;
                                try {
                                    fin = new FileInputStream(file);
                                    byte[] buff = new byte[fin.available()];
                                    fin.read(buff);
                                    base64 = Base64.encode(buff);
                                } catch (FileNotFoundException e) {
                                    e.printStackTrace();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                } finally {
                                    if (fin != null) {
                                        try {
                                            fin.close();
                                        } catch (IOException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }
                                return base64;
                            }
                        }
                    
                  
 

Previous Topic: Reset Phone Password

Feedback

0/500

Need help?

Click here and start chatting with us!