2

I am trying to upload an image to Tridion using CoreService. Upload is done using streamClient.UploadBinaryContent.

After upload I want to create an MultiMedia component from it. The code works fine on our staging environment. On pro environment the code only works on each third try (basically a 33% chance of success).

Giving the error :"Invalid value for property 'BinaryContent'. Unable to open uploaded file: C:\Windows\TEMP\tmp8EFA.jpg" when I try to save the MultiMedia Component.

My questions are:

  • How I can check if the upload was successfull?
  • What am I doing wrong?
  • Am I closing any streams too early?
  • Should I place a sleep timer somewhere to wait until the upload finshed?

Note: I do not have access to Tridion administration to check any settings.

I already included several catches and loops to retry, but I stripped these from the code snippet below.

string tempLocation = "";
        using (StreamUploadClient streamClient = GetNewUploadClient()) 
        {
            try
            {
                using (FileStream objfilestream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read))
                {
                    tempLocation = streamClient.UploadBinaryContent(fileInfo.Name.ToLower(), objfilestream);
                    objfilestream.Close();
                }
            }
            finally
            {
                if (streamClient.State == System.ServiceModel.CommunicationState.Faulted)
                    streamClient.Abort(); //never ended up in here
                else
                    streamClient.Close();
            }
        }

        ReadOptions readOptions = new ReadOptions() { LoadFlags = LoadFlags.Expanded };
        BinaryContentData binaryContent = new BinaryContentData();
        binaryContent.UploadFromFile = tempLocation;
        binaryContent.Filename = fileInfo.Name.ToLower();
        binaryContent.MultimediaType = new LinkToMultimediaTypeData() { IdRef = GetMultimediaTypeId(fileInfo.Extension) }; //typeids should be correct as it is working sometimes
        multimediaComponent.BinaryContent = binaryContent;

        IdentifiableObjectData savedComponent = null;
        try
            {
                savedComponent = GetNewCoreService().Save(multimediaComponent, readOptions); //this one fails
                break;
            }
            catch (Exception ex)
            { /* log and do a loop */ }

Appreciate any help. Thanks & bye

0

3 Answers 3

2

Do you have a load balancer between your client and the Core Service? That may cause the problem: if the load balancer sends the upload request to another CM backend server than the subsequent Save request, the stream is uploaded to a local temporary file on a different CM server than the one that handles the Save request (so that temporary file doesn't exist there). This is a known limitation in the current Core Service upload implementation (unfortunately you can't specify a file location for the temporary files, so you can't use an UNC location accessible by all CM backend servers).

1
  • Thats what I am currently looking into. I will update the question as soon as I have a result.Thanks
    – Moe
    Dec 10, 2014 at 10:41
1

The only thing I can think of is that you close the stream inside your using statement. Strictly speaking you shouldn't do it as it will be closed by the using statement.

Looking at exception it seems that it's failing on saving component, not on uploading binary. I would check that binary is correct at "C:\Windows\TEMP\tmp8EFA.jpg" on CM server. Does, retry of Save operation help? If so - it's IO problem and you could try to troubleshoot it with ProcMon, for instance.

Take a look at: http://amarchuk.blogspot.nl/2011/11/creating-multimedia-component-through.html

1

It's a long shot but are you running a virus scanner on the CM server? I've seen these kinds of problems where an antivirus product was blocking the upload for no apparent reason...

Other long shots:

  • outscaling? Are you running 3 WebGUI servers?
  • timeouts or size limitations? Does the size of the image make any difference?
  • IO issues? is the temp folder full of files (slows down directory enumerations) or the disk nearly full?
  • concurrency issues? Is your streamclient closing a trigger for the CM server to delete the temp file and does it come to soon?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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