RadAsyncUpoload upload to TargetFolder without postback

2 Answers 44 Views
AsyncUpload
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Fit2Page asked on 30 Nov 2023, 01:05 PM

Hi,

 

Is it possible to upload directly to the TargetFolder when the file is dropped on a dropzone?

I mean, without hitting a submit button first?

 

Thanks,

Marc

2 Answers, 1 is accepted

Sort by
0
Vasko
Telerik team
answered on 30 Nov 2023, 03:41 PM

Hello Marc,

You can find information relevant to your question in more detail in the following thread - RadAsyncUpload Automatic upload.

I hope this helps you out.

Kind regards,
Vasko
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
0
Vasko
Telerik team
answered on 30 Nov 2023, 04:39 PM

Hello again Marc,

As a follow-up, here's the code I used for testing: 

  • Markup of the AsyncUpload, AjaxManager, and the drop zones: 
    <telerik:RadAjaxManager runat="server" ID="ajaxManager" OnAjaxRequest="ajaxManager_AjaxRequest">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="ajaxManager">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="asyncUpload" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    
    <telerik:RadAsyncUpload 
        runat="server" 
        ID="asyncUpload" 
        TargetFolder="~/Uploads"
        DropZones=".DropZone1,#DropZone2"
        OnClientFileDropped="onClientFileDropped" 
        OnClientFileUploaded="onClientFileUploaded">
    </telerik:RadAsyncUpload>
    
    <div class="DropZone1">
        <p>Custom Drop Zone</p>
        <p>Drop Files Here</p>
    </div>
    <div id="DropZone2">
        <p>Custom Drop Zone</p>
        <p>Drop Files Here</p>
    </div>
  • Server-side logic: 
        protected void ajaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            if (e.Argument == "upload")
            {
                foreach (UploadedFile file in asyncUpload.UploadedFiles)
                {
                    file.SaveAs(Server.MapPath("~/your/folder/path") + file.FileName);
                }
            }
        }
  • JS logic that gets executed whenever a file is dropped and done uploading: 
    <script>
        function onClientFileDropped(sender, args) {
            $find("ajaxManager").ajaxRequest("upload");
        }
    
        function onClientFileUploaded(sender, args) {
            console.log("uploaded!") // Used for testing
        }
    </script>

Additionally, here are some articles released for the uploading process overall:

I hope this information suits you well.

Kind regards,
Vasko
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Tags
AsyncUpload
Asked by
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Vasko
Telerik team
Share this question
or