RadAsyncUpload Multiple File Upload and total upload size

Thread is closed for posting
7 posts, 1 answers
  1. Mahesh
    Mahesh avatar
    11 posts
    Member since:
    Oct 2012

    Posted 02 Aug 2013 Link to this post

    Hi All,

    Is there any way to get the total files size (upload size) in radasyncupload ? My requirement is, 
    I need to put multiple file RadAsyncUpload in my page. And have a total upload size limit (size of all files.) of 100 MB. When it reach the limit of 100 MB, it should display an error message and stops the uploading.

    The code I tried,

    <telerik:RadAsyncUpload runat="server" ID="AsyncUpload1" HideFileInput="true" Skin="Hay"
                            MultipleFileSelection="Automatic" AllowedFileExtensions=".jpeg,.jpg,.png,.doc,.docx,.xls,.xlsx,.rar,.zip,.txt,.dll,.pdf"
                            OnClientFileUploadFailed="onUploadFailed" OnClientFileSelected="onFileSelected"
                            OnClientFileUploaded="onFileUploaded" 
                            OnClientProgressUpdating="checkUploadedFilesSize"/>
    function OnFileUploaded(sender, args) {
        DecrementUploadsInProgress();
        var totalBytes = 0;
        var numberOfFiles = sender._uploadedFiles.length;
          
            if (isDuplicateFile) {
                sender.deleteFileInputAt(numberOfFiles - 1);
                isDuplicateFile = false;
                sender.updateClientState();
                alert("You can't add the same file twice");
                return;
            }
          
        for (var index in filesSize) {
            totalBytes += filesSize[index];
        }
        if (totalBytes > MAX_TOTAL_BYTES) {
            sender.deleteFileInputAt(numberOfFiles - 1);
            sender.updateClientState();
            alert(OVERSIZE_MESSAGE);
        }
    }

    This code is failing with an error "DOM is disabled".

    Is there any way to do this?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Aug 2013 Link to this post

    Hi Mahesh,

    Please have a look into this Code Library project on client side validation to restrict users from adding more than a pre-determined limit of files based upon total size of all uploaded files.

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mahesh
    Mahesh avatar
    11 posts
    Member since:
    Oct 2012

    Posted 05 Aug 2013 Link to this post

    Hi Shinu.

                    Thanks for the reply. But i gone through that code already. And tested that. It works only with single file upload. you can check the code i marked in my query. Thats the same code which is in the post send by you. :)

                    Please check the last part of the article which you provided. Its mentioned that,
    "P.S. I have only tested this with single file selection as it is what I needed for my project. I have no idea if all the same logic will work for multi-selection."


    Thanks,
    Mahesh
  5. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 07 Aug 2013 Link to this post

    Hi Mahesh,

    This sample works with multi file upload if it is enabled:
    <table>
        <tr>
            <td colspan="2">You may attach up to 20mb in files to the Email.</td>
        </tr>
        <tr>
            <td>Select File(s):</td>
            <td>
                <telerik:RadAsyncUpload ID="RadAsyncUpload1"                       
                    OnClientFileSelected="OnFileSelected"
                    OnClientFileUploadFailed="OnFileUploadFailed"
                    OnClientFilesUploaded="OnFilesUploaded"
                    OnClientProgressUpdating="OnProgressUpdating"
                    OnClientFileUploaded="OnFileUploaded"
                    OnClientFileUploadRemoved="OnFileUploadRemoved"
                    MultipleFileSelection="Automatic"
                    runat="server">
                </telerik:RadAsyncUpload>
            </td>
        </tr>
    </table>

    However it will work only with FF, Chrome, IE10. RadAsyncUpload uses different upload modules for the different browsers. Not all of them allow you to get file size on the client -only FileApi.

    Regards,
    Hristo Valyavicharski
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Mahesh
    Mahesh avatar
    11 posts
    Member since:
    Oct 2012

    Posted 07 Aug 2013 Link to this post


    Hi,

    Can you check my first post?
    MultipleFileSelection="Automatic"

    its already added in the tag. But not sure why its not working.


    Thanks,
    Mahesh
  7. Answer
    Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 07 Aug 2013 Link to this post

    Hi Manesh,

    Sample is attached. Please test it on Chrome, Firefox or IE10.

    Regards,
    Hristo Valyavicharski
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  8. Mahesh
    Mahesh avatar
    11 posts
    Member since:
    Oct 2012

    Posted 07 Aug 2013 Link to this post

    Hey Valyavicharski,

        Thanks for the sample. Its working fine. I checked the code. Mistake was mine. I put the file size check in OnClientFilesUploaded instead of OnClientFileUploaded. That was the mistake.

    Really thank a lot....


    Mahesh...
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017