Retrieve uploaded files

4 posts, 0 answers
  1. David
    David avatar
    12 posts
    Member since:
    Oct 2014

    Posted 15 Sep 2015 Link to this post

    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

  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 18 Sep 2015 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. David
    David avatar
    12 posts
    Member since:
    Oct 2014

    Posted 22 Sep 2015 in reply to Hristo Valyavicharski Link to this post

    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?
  5. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 23 Sep 2015 Link to this post

    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
Back to Top