我修正了你的错误 IBM。
在 com.ibm.watson.developer_cloud.discovery.v1.Discovery.createDocument(CreateDocumentRequest createRequest) 中,您可以看到正在构建的 Multipart 请求,而从未添加所需的元数据部分 (smh)。
我扩展了 Discovery 并添加了
multipartBuilder.addFormDataPart("metadata", createRequest.getMetadata().toString());
对请求...
public ServiceCall<CreateDocumentResponse> createDocument(CreateDocumentRequest createRequest) {
Validator.notEmpty(createRequest.getEnvironmentId(), "environment_id cannot be empty");
Validator.notEmpty(createRequest.getCollectionId(), "collection_id cannot be empty");
RequestBuilder builder = RequestBuilder.post(String.format("/v1/environments/%s/collections/%s/documents", new Object[] { createRequest.getEnvironmentId(), createRequest.getCollectionId() }));
if (createRequest.getConfigurationId() != null) {
builder.query(new Object[] { "configuration_id", createRequest.getConfigurationId() });
}
Validator.notNull(createRequest.getFile(), "Document file cannot be null");
MediaType mediaType = (MediaType)supportedMediaTypes.get(createRequest.getMediaType());
Validator.notNull(mediaType, String.format("Media Type '%s' not supported", new Object[] { createRequest.getMediaType() }));
RequestBody file = InputStreamRequestBody.create(mediaType, createRequest.getFile());
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
multipartBuilder.addFormDataPart("file", "filename", file);
multipartBuilder.addFormDataPart("metadata", createRequest.getMetadata().toString());
builder.body(multipartBuilder.build());
Request request = createVersionedRequest(builder);
return createServiceCall(request, ResponseConverterUtils.getObject(CreateDocumentResponse.class));
}