CloudUpload return an error

1 Answer 31 Views
CloudUpload
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
Benedikt asked on 07 Oct 2024, 01:11 PM

Hey guys,

I'm currently using the CloudUpload to upload files to an internal server.
This happens over multiple single steps in clsDaten.UploadReklamationsDateienKEMdoc.
This would return a true if succesfull uploaded and a false, as well as an error message if not.
I now want to show this error message in the interface and an Error sign instead of the succesfull check.
But I dont find anywhere how.

Does anyone have an idea?

Greetings Benedikt

    public class clsCloudUploadProvider : ICloudUploadProvider
    {
		long uploadFilesCount = 0;

		clsReklamation Reklamation;

		public Task<object> UploadFileAsync(string fileName, Stream fileStream, CloudUploadFileProgressChanged uploadProgressChanged, CancellationToken cancellationToken)
		{
			return Task.Factory.StartNew<object>(() => UploadFile(fileName, fileStream, uploadProgressChanged, cancellationToken), cancellationToken);
		}

		private object UploadFile(string fileName, Stream fileStream, CloudUploadFileProgressChanged uploadProgressChanged, CancellationToken cancellationToken)
		{
			this.uploadFilesCount++;
			var fileLength = fileStream.Length;

			uploadProgressChanged(fileLength);

			object[] ImportState = Import(fileStream, fileName);

			if ((bool)ImportState[0])
			{
				return fileName;
			}
			else
			{
				return null;
            }
		}

		public object[] Import(Stream filestream, string filename)
		{
			return clsDaten.UploadReklamationsDateienKEMdoc(Reklamation, (filestream as FileStream).Name);
		}

		public clsCloudUploadProvider(clsReklamation reklamation)
		{
			Reklamation = reklamation;
		}
	}


1 Answer, 1 is accepted

Sort by
1
Accepted
Martin Ivanov
Telerik team
answered on 08 Oct 2024, 09:55 AM

Hello Benedikt,

There is no direct API to mark the uploading file as failed, but you can use the following custom code:

private voidRadCloudUpload_ItemStateChanged(object sender, Telerik.Windows.Cloud.Controls.Upload.CloudUploadFileStateChangedEventArgs e)
 {
     if (e.NewState == CloudUploadFileState.Uploaded && e.Item.UploadResult == null) // this means that the UploadFile method in your provider returned null at some point
 {
         var methodInfo = typeof(CloudUploadFile).GetMethod("SetState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
         methodInfo.Invoke(e.Item, new object[1] { CloudUploadFileState.Failed });

        // you can use this code if you want to change the default tooltip of the state icon
 var container = cloudUploadList.ItemContainerGenerator.ContainerFromItem(e.Item);
         var notificationIcon = container.ChildrenOfType<Grid>().FirstOrDefault(x => x.Name == "NotificationIcon");
 notificationIcon.ToolTip = "File upload failed";
 }            
 }

You can use the ItemStateChanged event which will be invoked when you return the null valuein your UploadFile method. In this case the e.Item.UploadResult will be null, which you can use to indicate if the item should be marked as failed. Then, you can set its State to Failed and update the tooltip of the visual item if needed.

I hope this helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
commented on 09 Oct 2024, 06:15 AM

Hi Martin,

works exactly as I wanted,

thank you :)

Tags
CloudUpload
Asked by
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or