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