Код клиента
Вот код, который я использую на стороне клиента для проверки файла и отправки его на сервер в виде составного запроса.
Код: Выделить всё
private boolean sendFileDataToServer(JSONObject sendInfoData) throws IOException, JSONException {
Log.d(TAG, "sendFileDataToServer called");
// Initialize OkHttpClient and add logging interceptor
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build();
Log.d(TAG, "OkHttpClient initialized with NetworkInterceptor and logging");
// Extract file path from JSON data
String filePath = sendInfoData.optString("audio");
Log.d(TAG, "Extracted file path: " + filePath);
File file = new File(filePath);
// Initialize request body
RequestBody requestBody;
// If file path is "empty" or file does not exist, switch to a standard form request
if ("empty".equals(filePath) || !file.exists() || !file.isFile() || file.length()
Подробнее здесь: [url]https://stackoverflow.com/questions/79191148/android-file-metadata-missing-on-server-during-okhttp-multipart-upload[/url]
Мобильная версия