I am trying to upload binary images through the Java Client using Core Service API.
I am facing an issue while uploading the binary content using the IStreamUpload.uploadBinaryByteArray()
method. While invoking this method, I am getting the following exception:
The message with Action 'http://www.sdltridion.com/ContentManager/CoreService/2011/IStreamUpload/UploadBinaryByteArray' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).`
Can you please suggest what needs to be added to the below code to make it work?
public void createBinaryComponent(String title, String folderUri,
String schemaUri, ICoreService client, IStreamUpload streamUpload)
throws Exception {
// folder uri tcm:62-12340-2
// title PWRFTPXL
// schemaUril tcm:62-1523-8
ObjectFactory objectFactory = new ObjectFactory();
ReadOptions readOptions = new ReadOptions();
ComponentData newComponent = (ComponentData) client.getDefaultData(
ItemType.COMPONENT, "tcm:62-13493-2");
LinkToSchemaData schema = objectFactory.createLinkToSchemaData();
schema.setIdRef("tcm:62-1509-8");
newComponent.setSchema(schema);
newComponent.setComponentType(ComponentType.MULTIMEDIA);
newComponent.setTitle("PWRTESTGIF");
String customMetadata = "<Metadata xmlns=\"http://www.metlife.com/Schemas/Asset\"><AssetMeta><Title>pwrasset</Title><LongDescription>pwr</LongDescription></AssetMeta></Metadata>";
newComponent.setMetadata(customMetadata);
LinkToApprovalStatusData approvalStatus = new LinkToApprovalStatusData();
approvalStatus.setIdRef("tcm:0-0-0");
approvalStatus.setTitle("Undefined");
newComponent.setApprovalStatus(approvalStatus);
// UploadResponse us = new UploadResponse();
// D:\\13.4 release\\Power Reviews\\Test\\badge_vp_fr_CA.gif
// C:\\Users\\Public\\Pictures\\Sample Pictures\\Lighthouse.jpg
File file = new File(
"C:\\Users\\Public\\Pictures\\Sample Pictures\\Lighthouse.jpg");
file.setReadable(true);
file.setExecutable(true);
// FileInputStream fileinputStream = new FileInputStream(file);
// byte[] result = new byte[(int)file.length()];
//
byte[] bytearr = read("C:\\Users\\Public\\Pictures\\Sample Pictures\\Lighthouse.jpg");
String tempLoc = streamUpload.uploadBinaryByteArray(file.getName(),
bytearr);
BinaryContentData binaryData = new BinaryContentData();
// binaryData.setBinaryId(value);
binaryData.setFilename(file.getName());
newComponent.setIsBasedOnTridionWebSchema(true);
binaryData.setIsExternal(false);
// binaryData.setMimeType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
LinkToMultimediaTypeData multimeidatype = objectFactory
.createLinkToMultimediaTypeData();
multimeidatype.setIdRef("tcm:0-2-65544");
multimeidatype.setTitle("Jpeg image");
binaryData.setMultimediaType(multimeidatype);
binaryData.setUploadFromFile(tempLoc);
// newComponent.setId("tcm:0-0-0");
newComponent.setBinaryContent(binaryData);
client.create(newComponent, null);
}