I've tried everything I can think of to cancel the upload from within the ProcessStream() override and get a custom error on the client. (I am requiring a security token in the request, and if it doesn't validate I cancel the upload and would like to tell the user why).
On the server I'm setting both .Result and .AddReturnParam. On the client I'm listening for FileUploaded, UPloadCanceled, and UPloadFailed--only the UploadFailed event is hit. (Seems like the UploadCancelled should be hit even if cancelled from the server side--is this a bug?)
Inside UploadFailed, I check e.HandlerData.Message, e.ErrorMessage, and e.HandlerData.CustomData--my message is not in any of those places.
So, I have two questions: 1) am I doing the check and cancelling the download correctly? 2) How do I get a custom error message back to the client when doing a cancel?
public override void ProcessStream()
{
string token = this.Request.Form["token"];
if (!ValidateToken(token))
{
this.CancelRequest();
this.Result.Add("Error", "Security token is required. Please login.");
this.AddReturnParam("Error", "Security token is required. Please login.");
return;
}
Thank you,
DerrickM
6 Answers, 1 is accepted
Thank you for your interest in the RadUpload control.
Generally you are on the right way. There are only some small points you should change. Please follow the points below:
- The UploadCancelled event is a client-side initiated, i.e. you should not track it.
- The CancelRequest method will not cancel the server-side processing.
- To cancel the server-side processing you should return some parameters to the client.
- At the client-side track the FileUploadFailed event to notify the user that a Log-in is required.
Best wishes,
Ivan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
There's no way that I would have been able to figure that out on my own. I don't believe the documentation covers this kind of detail. (Update 5 return parameters inside the ProcessStream override in order to cancel the upload).
public override void ProcessStream()
{
token = this.Request.Form["token"];
if (string.IsNullOrEmpty(token) || !ValidateToken(token))
{
this.AddReturnParam(RadUploadConstants.ParamNameMessage, "Security token is required. Please login.");
string fileName = this.Request.Form[RadUploadConstants.ParamNameFileName];
string filePath = this.GetFilePath(fileName);
this.AddReturnParam(RadUploadConstants.ParamNameSuccess, false);
this.AddReturnParam(RadUploadConstants.ParamNameFileIdent, filePath);
this.AddReturnParam(RadUploadConstants.ParamNameFileName, fileName);
this.AddReturnParam(RadUploadConstants.ParamNameFilePath, filePath);
this.AddReturnParam(RadUploadConstants.ParamNameFinalFileRequest, true);
return;
Thank you for the hint at the missing documentation. We found that whole the branch with the RadUpload API is missing from our online documentation. Regarding your report we updated your Telerik points.
Once again thank you.
Greetings,
Ivan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Maybe I did not find the correct entries but I find the radupload documentation still lacks details about how to handle the files server side.
My requirement is the following. I need to :
- upload a file (csv for example)
- import the file content to my database
Where is the correct place to handle the uploaded file. It looks like it's in SaveChunkData.
Here is my server side code:
public
override
bool
SaveChunkData(
string
filePath,
long
position,
byte
[] buffer,
int
contentLength,
out
int
savedBytes)
{
bool
result =
base
.SaveChunkData(filePath, position, buffer, contentLength,
out
savedBytes);
// Checks if this is the last chunk of the file
if
(
this
.IsFinalFileRequest())
{
//if the file is successfully uploaded
if
(result)
{
string
fileName =
this
.GetFileName();
ProcessUploadedFile(fileName);
}
}
return
result;
}
// Logic that will deal with the uploaded files
private
void
ProcessUploadedFile(
string
fileName)
{
// TODO: Add your logic here
}
How do I send back to the client that my file was imported correctly or not?
How do I handle that result correctly on the client?
In case my file processing takes some time, how can I display on the client that the server is processing the file, eventually with progres notification?
Please, explain me how to do and then add it to the documentation...
That would help me a lot.
Thank you for your help,
John.
You can send a message to the clien in the SaveChunkData method using the AddReturnFileParam, like so :
if (this.IsFinalUploadRequest())
{
...
this.AddReturnFileParam(RadUploadConstants.ParamNameMessage, "correctly uploaded");
}
void upload_FileUploaded(object sender, FileUploadedEventArgs e)
{
e.HandlerData.Message;
}
Please let us know if you have questions on this matter.
Kind regards,
Alex Fidanov
the Telerik team
Please add to the documentation the usage of all the constants in RadUploadConstants...
Thanks,
Best regards,
John.