Telerik Forums
Kendo UI for jQuery Forum
6 answers
1.3K+ views

Hello,

I am new to KendoUI web and using basic Jquery widget for uploading/dropping PDF file. I want to convert uploaded PDF file into Base64 string and then pass that data on to Restfull API(C#) to be saved in database.

 I did not find a way to achieve this in this section of the forums. Can anyone please help on how to do this or point me into right direction please??

Sample code would be great help if anyone got it please !!

Thanks

Aleksandar
Telerik team
 answered on 19 Jan 2021
2 answers
1.0K+ views

I am trying to use async chunk upload with Web API 2.
But always after first chunk I am receiving message “Cannot read property 'chunkIndex' of undefined”.
What did I do wrong?

 

using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Web;
using System.Web.Hosting;
using System.Web.Http;
 
namespace UploadWebApi.Controllers
{
    public class UploadController : ApiController
    {
        [DataContract]
        public class ChunkMetaData
        {
            [DataMember(Name = "uploadUid")]
            public string UploadUid { get; set; }
            [DataMember(Name = "fileName")]
            public string FileName { get; set; }
            [DataMember(Name = "contentType")]
            public string ContentType { get; set; }
            [DataMember(Name = "chunkIndex")]
            public long ChunkIndex { get; set; }
            [DataMember(Name = "totalChunks")]
            public long TotalChunks { get; set; }
            [DataMember(Name = "totalFileSize")]
            public long TotalFileSize { get; set; }
        }
 
        public class FileResult
        {
            public bool Uploaded { get; set; }
            public string FileUid { get; set; }
        }
 
        public class Files
        {
            public string Extension { get; set; }
            public string Name { get; set; }
            public int Size { get; set; }
            public string Uid { get; set; }
        }
 
        public IHttpActionResult Save(HttpFileCollection files)
        {
            string path = String.Empty;
            if (files != null)
            {
                for (var i = 0; i < files.Count; i++)
                {
                    path = Path.Combine(HostingEnvironment.MapPath("~/App_Data"), files[i].FileName);
                    files[i].SaveAs(path);
                }
            }
            return Ok("");
        }
 
        public IHttpActionResult Remove(string[] fileNames)
        {
            if (fileNames != null)
            {
                foreach (var fullName in fileNames)
                {
                    var fileName = Path.GetFileName(fullName);
                    var physicalPath = Path.Combine(HostingEnvironment.MapPath("~/App_Data"), fileName);
                    if (File.Exists(physicalPath))
                    {
                        File.Delete(physicalPath);
                    }
                }
            }
            return Ok("");
        }
 
        public void AppendToFile(string fullPath, Stream content)
        {
            try
            {
                using (FileStream stream = new FileStream(fullPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
                {
                    using (content)
                    {
                        content.CopyTo(stream);
                    }
                }
            }
            catch (IOException ex)
            {
                throw ex;
            }
        }
 
        public IHttpActionResult ChunkSave()
        {
            var files = HttpContext.Current.Request.Files;
            var metaData = HttpContext.Current.Request.Form["metadata"];
            if (metaData == null)
            {
                return Save(files);
            }
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(metaData));
            var serializer = new DataContractJsonSerializer(typeof(ChunkMetaData));
            ChunkMetaData somemetaData = serializer.ReadObject(ms) as ChunkMetaData;
            string path = String.Empty;
            if (files != null)
            {
                for (var i = 0; i < files.Count; i++)
                {
                    path = Path.Combine(HostingEnvironment.MapPath("~/App_Data"), somemetaData.FileName);
                    AppendToFile(path, files[i].InputStream);
                }
            }
            FileResult fileBlob = new FileResult();
            fileBlob.Uploaded = somemetaData.TotalChunks - 1 <= somemetaData.ChunkIndex;
            fileBlob.FileUid = somemetaData.UploadUid;
            return Json(fileBlob);
        }
    }
}
Alexander
Top achievements
Rank 2
 answered on 30 Dec 2020
2 answers
2.7K+ views

Doing it this way:

var uploadFile = $("#documents-files").data("kendoUpload");

var file2 = uploadFile.getFiles();

formData.append('files2',file2[0]);

$.ajax({ url: 'foo.php', type: 'POST', data: formData, async: false, cache: false, contentType: false, enctype: 'multipart/form-data', processData: false, success: function (response) { console.log(response); } });

 

And in PHP server var_dump($_POST) :

array(1) {["files2"]=>string(15) "[object Object]"}

 

And $_FILES is empty.

 

 

If I send file in standard way, WITHOUT KendoUpload widget 

 var files = document.getElementById('documents-files');
 var file = files.files[0];

it works, superglobal $_FILES is filled with file data.

kumara
Top achievements
Rank 1
 answered on 26 Nov 2020
11 answers
1.3K+ views

Hello,

  We are having a problem uploading multiple files on a server running HTTP/2.  Single files upload fine.  I used the "batch" property and that seems to work ok since it's one request.  We disabled HTTP/2 and went back to HTTP/1.1.  Everything seemed to work fine.
I downloaded the newest trial version it is still has the problem. Is there any way around this issue without using the "batch" property?

Thanks in advance!

Martin
Telerik team
 answered on 25 Nov 2020
1 answer
77 views

Hello!

I want to display initial list of files, but I don't want to use 'async' mode.

As I see in the docs, this feature works well in async mode https://docs.telerik.com/kendo-ui/api/javascript/ui/upload/configuration/files

But it doesn't work without 'async' setting https://dojo.telerik.com/UVOmAtIM

Is it bug or not?

Thanks!

Bill
Top achievements
Rank 1
 answered on 29 Oct 2020
3 answers
313 views

Hi,

Is it possible to set the dropZone dynamically?

 

 

Petar
Telerik team
 answered on 16 Oct 2020
5 answers
650 views
I am using Upload MVC in our application and file list is hidden by default in our app.  But Upload still show upload status below the upload button. How to hide the status data?

<strong class="k-upload-status k-upload-status-total">Done<span class="k-icon k-warning">uploaded</span></strong>
Ivan Danchev
Telerik team
 answered on 01 Sep 2020
8 answers
800 views
I'm using the upload widget and have a problem receiving files server side in an mvc controller.

Javascript code:
 $("#file-upload").kendoUpload({
            async: {
                saveUrl: '@Url.Action("UploadFiles")',
                autoUpload: false
            },
            upload: function(e) {
            }
        });

Controller signature: public ActionResult UploadFiles(IEnumerable<HttpPostedFileBase> files)

When I debug into the controller method files is null. If I debug into the upload event on the widget I see that it contains the files. Looking at fiddler I also see that the data is sent to the server.



Martin
Telerik team
 answered on 03 Aug 2020
2 answers
445 views

Hi,

I'm having the same problem. I already check the name input matching the controller parameter, but still getting a null  IEnumerable<HttpPostedFileBase>. I'm out of new solutions, so any help will be appreciated.

Please, find my project in attach. I try via normal-save and chunck-mode, without sucess. 

Best regards, 

Leandro Alves

Martin
Telerik team
 answered on 03 Aug 2020
3 answers
106 views

Hi 😊

I need some help. I was using kendo for uploading files into sharepoint 2013. After migration to sp 2016 the same code generates different response from server (it is without 'd' and it starts with odata.metadata - the old working one has 'd' and __metadata). Is the odata different and that causes issues? Any help would be appreciated. Thanks.

Ivan Danchev
Telerik team
 answered on 29 Jul 2020
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?