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
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);
}
}
}
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.
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!
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!
Hi,
Is it possible to set the dropZone dynamically?
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
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.