HELP!!!! How to upload a file?

HELP!!!! How to upload a file?

krupal.jadhavkrupal.jadhav Posts: 14Questions: 6Answers: 0
edited July 2018 in Free community support

I am unable to upload a file to the server. As soon as I click Choose file..., a server error is thrown even before send the file to server:

Here is my upload code:

    var csvForm = new $.fn.dataTable.Editor({
        ajax: {
            create: {
                type: 'POST',
                url: fileurl,
                headers: {
                    'Authorization': 'Bearer ' + session_token,
                }
            },

        },

        table: "#employee",

        idSrc: 'dtrowId',

        fields: [{
            label: "CSV:",
            name: "csv_file",
            type: "upload",
            display: function ( file_id ) {
                return '<img src="'+editor.file( 'files', file_id ).web_path+'"/>';
            },
            clearText: "Clear",
        }]

    });

Answers

  • kthorngrenkthorngren Posts: 21,244Questions: 26Answers: 4,929

    What is the error the server is returning?

    Kevin

  • krupal.jadhavkrupal.jadhav Posts: 14Questions: 6Answers: 0

    @kthorngren ,

    The file is not being sent to the server. I am not even clicking on the upload button. Just the choose file option is giving me the server error.

  • allanallan Posts: 63,331Questions: 1Answers: 10,436 Site admin

    I think Kevin's point is, what data is the server returning, if you have a look in the Network Inspector of your browser? The error you are seeing means that invalid JSON was returned from the upload, the cause could be anything from a script error to permissions.

    Checking the response from the server would let you (and us) know if there are any error messages coming back from the server.

    If there aren't, you'd need to refer to the server's error logs to determine what the fault is.

    Allan

  • krupal.jadhavkrupal.jadhav Posts: 14Questions: 6Answers: 0

    Hi @allan ,
    In browser it says 405 method not allowed. But for some reason the request URL is the URL of my web page and not the server URL that I have specified in my code.

  • krupal.jadhavkrupal.jadhav Posts: 14Questions: 6Answers: 0

    @allan and @kthorngren

    I am not writing any server code as I am simply using plain Javascript, HTML and REST api for my application. Can I do a file upload without writing any server side code?

  • allanallan Posts: 63,331Questions: 1Answers: 10,436 Site admin

    Can I do a file upload without writing any server side code?

    See your duplicate question here which I've added a reply to.

    Allan

This discussion has been closed.