Editor File upload

Editor File upload

klymov.inekonklymov.inekon Posts: 40Questions: 12Answers: 0

Hi, I have a question about file uploading.

I tried to download the .exe file (such requirements). During a example upload, it caused the page to refresh. I got around this by adding it to the ajax field.

{
    name: 'File',
    data: 'File',
    label: 'File',
...
    type: 'upload',
    attr: {
        accept: ".exe,.msi",
    },

    ajax: function (files, done) {
        if (files.length == 0) return;
        done(files)
    },

    display: function (file) {
        return `<span> ${file.name} </span>`;
    },

},

It worked, and when I submit, I see in the data that the field has a value with the type FILE.


create: { type: 'POST', url: 'route', data: function (d) { debugger var file = d.data[0].ClientVersion.File; // file exist return d; }, },

But then I've an errors

jquery.js:10073  Uncaught TypeError: Illegal invocation
jquery.js:10073  Uncaught (in promise) TypeError: Failed to execute 'arrayBuffer' on 'Blob': Illegal invocation

I've tried to set contentType but it not helped.

    contentType: 'application/x-www-form-urlencoded',

What should I do to send it to .net editor endpoint?

I don't need this file saved on server some way. I need to store it to database via MemoryStream. I've set for now in endpoint

.SetFormatter((val,data)=>{
    var file = val as IFormFile;
    if(file is null) return null;
    using (var memoryStream = new MemoryStream())
    {
        file.CopyTo(memoryStream);
        var fileContent = memoryStream.ToArray();
        return fileContent;
    }
}),

Maybe some solution to do this in js before sending file, rewrite field into byte array and send like standard value?

Answers

  • allanallan Posts: 65,588Questions: 1Answers: 10,904 Site admin

    I tried to download the .exe file

    Do you mean you are trying to upload an exe via Editor? I don't provide a Windows executable for any DataTables software. There is a .NET demo package for Editor which includes a DLL though.

    What should I do to send it to .net editor endpoint?

    You shouldn't need to do anything other than set the ajax url. The demo should accept files and the server will then process them (and in this case reject an exe). Is that not happening for you in that example?

    Allan

  • allanallan Posts: 65,588Questions: 1Answers: 10,904 Site admin

    Also, for a custom upload action, check out the documentation here. A set formatter isn't the right place to handle the file.

    Allan

Sign In or Register to comment.