Ubuntu 22.04
Docker deployment of Dify 1.11.0
Issue 1: When I use Java to call the Dify API to upload an image to the Dify knowledge base, an error occurs. However, uploading regular document files does not result in any error.
But when using the Dify visual platform to directly add image files on the knowledge base page, there is no error.
Java calling code
// Prepare multipart request
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.set("Authorization", "Bearer " + apiKey);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", new FileSystemResource(file));
// "/home/ruoyi/uploadPath/01.jpeg"
// Build data JSON object, including indexing_technique, process_rule, and doc_form
String dataJson = String.format(
"{\"indexing_technique\":\"high_quality\",\"process_rule\":{\"mode\":\"automatic\"},\"doc_form\":\"%s\"}",
docForm
);
body.add("data", dataJson);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
String url = difyApiUrl + "/datasets/" + datasetId + "/document/create-by-file";
ResponseEntity<Map> response = restTemplate.postForEntity(url, requestEntity, Map.class);
Response error
400 BAD REQUEST: “{"code":"invalid_param","message":"","status":400}\n”