Я пишу код для записи звука в начале, когда мы нажимаем кнопку, которую нужно загрузить на сервер. Я использую модификацию: я использую два разных API модификации. Один для данных форума, а другой для загрузки аудио.
Я получил эту ошибку:
java.lang.IllegalArgumentException: API declarations must be interfaces.
Активность:
private void uploadAudio() {
Long date = new Date().getTime();
Date current_time = new Date(Long.valueOf(date));
String file_path = getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getPath() + "/" + current_time + ".3gp";
File audioFile = new File(file_path);
RequestBody requestFile = RequestBody.create(MediaType.parse("audio/*"), audioFile);
MultipartBody.Part audioPart = MultipartBody.Part.createFormData("audio", audioFile.getName(), requestFile);
ApiService apiService = ApiClient.getClient().create(ApiService.class);
Call<ResponseBody> call = apiService.uploadAudio(audioPart);
call.enqueue(new retrofit2.Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
if (response.isSuccessful()){
if (response.body().toString().equals("200")){
Toast.makeText(getApplicationContext(), "Audio uploaded Successfully", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(getApplicationContext(),"Audio Upload Failed", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(getApplicationContext(), t.toString(), Toast.LENGTH_SHORT).show();
}
});
API
public class ApiService {
@Multipart
@POST("retroapi2.php")
Call<ResponseBody> uploadAudio(@Part MultipartBody.Part audio) {
return null;
}
}
public class ApiClient {
private static final String BASE_URL = "http://mysite.in/atmedia/ud/";
private static Retrofit retrofit;
public static Retrofit getClient() {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
if ($_SERVER['REQUEST_METHOD']=='POST'){
//Getting post data
$fileName = $_FILES['audio']['name'];
$tempPath = $_FILES['audio']['tmp_name'];
$fileSize = $_FILES['audio']['size'];
$upload_path = 'upload/'; // set upload folder path
require_once('retconfig.php');
//Creating an SQL Query to insert into database
//Here you may need to change the retrofit_users because it is the table I created
//if you have a different table write your table's name
//This query is to check whether the username or email is already registered or not
$sql = "SELECT * FROM demo WHERE mobile='$mobile'";
//If variable check has some value from mysqli fetch array
//That means username or email already exist
$check = mysqli_fetch_array(mysqli_query($con,$sql));
//Checking check has some values or not
if (isset($check)){
//If check has some value that means username already exist
echo 'username or email already exist';
}else{
//If username is not already exist
//Creating insert query
if ($fileSize < 5000000){
move_uploaded_file($tempPath, $upload_path . $fileName); // move file from system temporary path to our upload folder path
}
Это ваша проблема:
public class ApiService {
@Multipart
@POST("retroapi2.php")
Call<ResponseBody> uploadAudio(@Part MultipartBody.Part audio) {
return null;
}
}
ApiService
должен быть interface
:
public interface ApiService {
@Multipart
@POST("retroapi2.php")
Call<ResponseBody> uploadAudio(@Part MultipartBody.Part audio);
}
Дополнительную информацию см. в документации по модернизации.
Ошибка говорит вам, что вам нужно изменить.