This is a migrated thread and some comments may be shown as answers.

Retrieve uploaded files

3 Answers 105 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 15 Sep 2015, 10:16 AM

Hi guys,

I've a problem with RadAsyncUpload control:
I've a project with disabled viewstate, and every single action is performed using pagemethods, now the problem is that when the user upload a file the OnFileUploaded event is not firing, and I don't know how to retrieve the uploaded files in a next step, since I'm using just pagemethods and don't have a reference to the RadAsyncUpload instance 

Is there some way to retrieve the uploaded file in the moment in that are sent or also in a next step using a pagemethod?

Sorry for my very poor english

3 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 18 Sep 2015, 06:55 AM
Hello David,

Thank you for contacting Telerik support.

The OnFileUploaded event should be fired only if postback is caused, even if ViewState is disabled. Other option to upload file is to use Custom Http Handler to upload files instead using OnFileUploaded event.

Sample here:
https://github.com/hvalyavicharski/telerik-radcontrols/tree/master/RadAsyncUpload/RadAsyncUpload_CustomHandler

Online demo:
http://demos.telerik.com/aspnet-ajax/asyncupload/examples/imageuploader/defaultcs.aspx

Regards,
Hristo Valyavicharski
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
David
Top achievements
Rank 1
answered on 22 Sep 2015, 02:58 PM
wow, very helpfull, I didn't know this possibility, however there is again a problem, how can I retrieve in a next step, using a web method, the uploaded image? 
I can save the name of the image on the db or in a hidden field, but isn't there a solution more "clean" already available by Telerik?
0
Hristo Valyavicharski
Telerik team
answered on 23 Sep 2015, 01:12 PM
You can create and return custom result back to the client after the file is uploaded through the handler:
using System;
using Telerik.Web.UI;
  
// The result object is returned from the handler to the page.
// You can include custom fields in the result by extending the AsyncUploadResult class.
// In this case we return the ID of the image record.
public class SampleAsyncUploadResult : AsyncUploadResult
{
    private int imageID;
  
    public int ImageID
    {
        get { return imageID; }
        set { imageID = value; }
    }
}
window.fileUploaded = function (sender, args) {
       var id = args.get_fileInfo().ImageID;
 
       $(".imageContainer")
           .html("")
           .append($("<img />")
           .attr("src", getImageUrl(id)));
 
       $(".info").html(String.format("<strong>{0}</strong> successfully inserted.<p>Record ID - {1}</p>", args.get_fileName(), id));
 
   };

Browse the source of this demo: AsyncUpload - Custom Http Handler

Regards,
Hristo Valyavicharski
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
AsyncUpload
Asked by
David
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
David
Top achievements
Rank 1
Share this question
or