7

I am new to tridion and I want to Create a multimedia component and I have written the below code.

import com.sdltridion.contentmanager.coreservice.ICoreService;
import com.sdltridion.contentmanager.coreservice.ICoreServiceCreateCoreServiceFaultFaultFaultMessage;
import com.sdltridion.contentmanager.coreservice.ICoreServiceGetDefaultDataCoreServiceFaultFaultFaultMessage;
import com.sdltridion.contentmanager.r6.ArrayOfItemType;
import com.sdltridion.contentmanager.r6.FileExtensionsList;
import com.sdltridion.contentmanager.r6.ItemType;
import com.sdltridion.contentmanager.r6.LinkToSchemaData;
import com.sdltridion.contentmanager.r6.MultimediaTypeData;
import com.sdltridion.contentmanager.r6.ObjectFactory;
import com.sdltridion.contentmanager.r6.OrganizationalItemItemsFilterData;
import com.sdltridion.contentmanager.r6.ReadOptions;

public class MultimediaComponentUpload {

     public static void getMultimediaUpload(ICoreService endpoint, String
     title)
     throws ICoreServiceGetDefaultDataCoreServiceFaultFaultFaultMessage,
     ICoreServiceCreateCoreServiceFaultFaultFaultMessage {


     ObjectFactory objectFactory = new ObjectFactory();

     ArrayOfItemType itemTypes = objectFactory.createArrayOfItemType();

     itemTypes.getItemType().add(ItemType.MULTIMEDIA_TYPE);


     OrganizationalItemItemsFilterData filter = objectFactory
     .createOrganizationalItemItemsFilterData();
     filter.setItemTypes(objectFactory
     .createItemsFilterDataItemTypes(itemTypes));

     MultimediaTypeData multimediaTypeData = (MultimediaTypeData) endpoint
     .getDefaultData(ItemType.MULTIMEDIA_TYPE, "tcm:246-95-2");
     multimediaTypeData.setMimeType(objectFactory
     .createBinaryContentDataMimeType("tcm:0-2-65544"));
     FileExtensionsList fileExtensionsList = objectFactory.createFileExtensionsList();
     fileExtensionsList.getFileExtension().add(".png");
     fileExtensionsList.getFileExtension().add(".jpg");
     fileExtensionsList.getFileExtension().add(".bmp");

      fileExtensionsList.getFileExtension().add(".jpg");

     multimediaTypeData.setFileExtensions(objectFactory
     .createFileExtensionsList(fileExtensionsList));


     LinkToSchemaData schema = objectFactory.createLinkToSchemaData();

     schema.setIdRef(objectFactory.createLinkIdRef("tcm:246-243-8"));


     multimediaTypeData.getTitle().setValue(title);
     System.out.println(multimediaTypeData.getId());

     endpoint.create(multimediaTypeData, new ReadOptions());
     }
     }

When I try to run the program I am facing an Exception

Exception: Exception in thread "main" com.sdltridion.contentmanager.coreservice.ICoreServiceCreateCoreServiceFaultFaultFaultMessage: Invalid value for property 'FileExtensions'. Field 'FileExtensions' is mandatory. You must fill in this field before you can save.

Can any one help me out with this issue...

Thanks in advance....

9

Your code is creating a Multimedia Type (which you need when creating a Multimedia Schema).

To create a Multimedia Component you will first need to upload the binary data to the Content Manager, and then you create the Component and set its Multimedia Properties. Here is some sample code in C#, but it should give you a rough idea:

string myFilename = "picture.jpg";
string extension = myFilename.Substring(myFilename.LastIndexOf('.') + 1);
string tempPath;

// upload binary content to cms 
using (StreamUploadClient suClient = new StreamUploadClient("streamUpload_netTcp_2012"))
{
    tempPath = suClient.UploadBinaryContent(myFilename, myBinaryContentStream);
}

// create tcm item
var mmComponent = new ComponentData
{
    Id = "tcm:0-0-0",
    Title = myTitle,
    Schema = new LinkToSchemaData { IdRef = "tcm:1-22-8" },
    LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = "tcm:1-33-2" } }
};

// put binary data in tcm item
using (SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2012"))
{
    // find multimedia type
    var list = client.GetSystemWideList(new MultimediaTypesFilterData());
    var multimediaType = list.OfType<MultimediaTypeData>().Single(mt => mt.FileExtensions.Contains(extension));

    // set BinaryContent of a component
    mmComponent.BinaryContent = new BinaryContentData
    {
        UploadFromFile = tempPath,
        Filename = myFilename,
        MultimediaType = new LinkToMultimediaTypeData { IdRef = multimediaType.Id }
    };

    // create (and save) component
    ComponentData data = (ComponentData)client.Create(mmComponent, new ReadOptions());
    string uriAfterSave = data.Id;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.