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

drag and drop bulk upload and validations

3 Answers 314 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Member12221
Top achievements
Rank 1
Member12221 asked on 14 Jul 2017, 04:40 AM

I'm using kendo upload and want to know how I can validate the bulk upload on file size. (I don't need to upload files which are sized more than 3 MB, but the other files should upload). I have done it in the following way and it drops out the file which is too big and fails to upload the other documents which comes after the error file.

    <div class="demo-section k-content">
        @(Html.Kendo().Upload()
        .Name("files")
        .Async(a => a
            .Save("ChunkSave", "FileUpload")
            .Remove("Remove", "FileUpload")
            .AutoUpload(true)
            .ChunkSize(1100)
        )
        .Validation(validation => validation.AllowedExtensions(new string[] { ".docx", ".doc", ".pdf" }))
        .Validation(validation => validation.MaxFileSize(3145728))
        .DropZone(".whole-section")
        .Events(events => events
        .Cancel("onCancel")
        .Clear("onClear")
        .Complete("onComplete")
        .Error("onError")
        .Progress("onProgress")
        .Remove("onRemove")
        .Select("onSelect")
        .Success("onSuccess")
        .Upload("onUpload")
            )
        )
    </div>

Let me know if there is a way to only drop the files which are in error state (too big, doc type)

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Danchev
Telerik team
answered on 17 Jul 2017, 11:28 AM
Hello,

I tested the Upload's behavior using your configuration and as you can see in this short screencast the file that does not pass the validation (larger than 3MB) does not prevent the other file (smaller than 3MB) from being uploaded. Are there any other steps that we need to followed in order to reproduce the issue or custom logic in the Upload's event handler that might be interfering with the Upload's default behavior? I tested it with no handlers attached, but I can see from the code snippet you posted that you are attaching event handlers for many of the Upload's events.

Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Member12221
Top achievements
Rank 1
answered on 18 Jul 2017, 05:46 AM

Hi Ivan, 

Thanks a lot for the quick response. I have the following controller code which i took from chunk save example. 

        public ActionResult ChunkSave(IEnumerable<HttpPostedFileBase> files, string metaData)
        {
            if (metaData == null)
            {
                //return Save(files);
            }

            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(metaData));
            var serializer = new DataContractJsonSerializer(typeof(ChunkMetaData));
            ChunkMetaData chunkData = serializer.ReadObject(ms) as ChunkMetaData;
            string path = String.Empty;
            // The Name of the Upload component is "files"
            if (files != null)
            {
                foreach (var file in files)
                {
                    path = Path.Combine(Server.MapPath("~/Uploads"), chunkData.FileName);

                    AppendToFile(path, file.InputStream);
                }
            }

            FileResult fileBlob = new FileResult();
            fileBlob.uploaded = chunkData.TotalChunks - 1 <= chunkData.ChunkIndex;
            fileBlob.fileUid = chunkData.UploadUid;

            return Json(fileBlob);
        }

when the error file is in the last of the queue, other files are uploaded as expected. but if the error files come before the normal files the upload is in a kind of "paused" state. see the attached. 

kindly let me know your insights. 

If you can share your code with me, i can try the controller code you are using and see the difference. 

Thanks

chathura

 

0
Member12221
Top achievements
Rank 1
answered on 19 Jul 2017, 10:07 AM

Hi Ivan, 

I fixed the issue. turned out that we did not want the chunk upload. just an asynchronous upload did the trick. now I'm able to do all the validations without interfering with the other files. 

Thanks heaps for your help and guidance. 

Tags
Upload
Asked by
Member12221
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Member12221
Top achievements
Rank 1
Share this question
or