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

RadAsyncUpload Multiple File Upload and total upload size

6 Answers 701 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Mahesh
Top achievements
Rank 1
Mahesh asked on 02 Aug 2013, 06:15 AM
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?

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Aug 2013, 09:32 AM
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.
0
Mahesh
Top achievements
Rank 1
answered on 05 Aug 2013, 09:38 AM
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
0
Hristo Valyavicharski
Telerik team
answered on 07 Aug 2013, 07:16 AM
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.
0
Mahesh
Top achievements
Rank 1
answered on 07 Aug 2013, 07:56 AM

Hi,

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

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


Thanks,
Mahesh
0
Accepted
Hristo Valyavicharski
Telerik team
answered on 07 Aug 2013, 11:17 AM
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.
0
Mahesh
Top achievements
Rank 1
answered on 07 Aug 2013, 11:39 AM
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...
Tags
Upload (Obsolete)
Asked by
Mahesh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mahesh
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Share this question
or