Я хочу сохранить как графические, так и строковые данные на сервере, используя модифицированную составную часть, но я получаю сообщение об ошибке «500 Internal Server Error» здесь https://prnt.sc/p95pe7
API работает нормально на Postman, но естьэто ошибка при модернизации
@Multipart
@POST("item_app")
Call<ItemAddResponse> addNewItem(@Part MultipartBody.Part file,
@Part("name") RequestBody name,
@Part("description") RequestBody description,
@Part("tags") RequestBody tags,
@Part("category") RequestBody category,
@Part("stock_status") RequestBody stock_status,
@Part("sku") RequestBody sku,
@Part("quantity") RequestBody quantity,
@Part("pcs_per_box") RequestBody pcs_per_box,
@Part("price") RequestBody price,
@Part("safe_quantity") RequestBody safe_quantity,
@Part("remarks") RequestBody remarks
);
И я использую это так
Call<ItemAddResponse> call = NetworkConfig.getApiService().addNewItem(
NetworkConfig.createFilePartFromFile("profile_img", finalImagePath),
NetworkConfig.createPartFromString(name),
NetworkConfig.createPartFromString(description),
NetworkConfig.createPartFromString(tags),
NetworkConfig.createPartFromString(category),
NetworkConfig.createPartFromString(stockStatus),
NetworkConfig.createPartFromString(sku),
NetworkConfig.createPartFromString(quantity),
NetworkConfig.createPartFromString(pcsPerBox),
NetworkConfig.createPartFromString(price),
NetworkConfig.createPartFromString(safeQuantity),
NetworkConfig.createPartFromString(remarks)
);
call.enqueue(new Callback<ItemAddResponse>() {
@Override
public void onResponse(Call<ItemAddResponse> call, Response<ItemAddResponse> response) {
if (response.isSuccessful()) {
Utility.getInstance().hideProgressDialog();
ItemAddResponse itemAddResponse = null;
if (response.body() != null) {
itemAddResponse = response.body();
}
Log.d(TAG, "Response addNewItemService : " + itemAddResponse);
if ( itemAddResponse.getStatus() == 200 ) {
ItemAddDialog itemAddDialog = ItemAddDialog.newInstance();
((ItemAddDialog) itemAddDialog).setCallback(new ItemAddDialog.Callback() {
@Override
public void onActionClick() {
finish();
}
});
itemAddDialog.show(getSupportFragmentManager(), "tag");
}
} else {
Utility.getInstance().hideProgressDialog();
}
}
@Override
public void onFailure(Call<ItemAddResponse> call, Throwable t) {
Utility.getInstance().hideProgressDialog();
Utility.dialogError(AddNewItemActivity.this, t.getLocalizedMessage());
}
});
Где я использую эту функцию для добавления строки
@NonNull
public static RequestBody createPartFromString(String descriptionString) {
if (descriptionString == null)
return null;
return RequestBody.create(okhttp3.MultipartBody.FORM, descriptionString);
}
и этоФункция использования для добавления файла
@NonNull
public static MultipartBody.Part createFilePartFromFile(String partName, String file_path) {
MultipartBody.Part body = null;
if (file_path != null) {
File file = new File(file_path);
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
body = MultipartBody.Part.createFormData(partName, file.getName(), requestFile);
return body;
}
return null;
}
Спасибо