Nodejs/Express Save select avatar from web client and save directly to MySQL Database









up vote
0
down vote

favorite












Looking for some guidance here. I am building Nodejs/Express app with MySQL Database. I want to be able to click on the users image on the web page (initial image is generic), select a different image and upload/save new image into MySQL database. I using:



$('#file-input').trigger('click').change (function()
alert($('#file-input').val());
)


I get C:/fakepath... for image location. I would like to how to upload/save selected image to the MySQL database. Connection to database is established, and routes for regular data work just fine.










share|improve this question























  • "I want to be able to click on the users image on the web page (initial image is generic), select a different image and upload/save new image into MySQL database" - You simply can not do it, you can't access to the local file system on behalf of the user, think about the security implications of having this type of feature
    – Alon Eitan
    Nov 11 at 17:09











  • I understand all security implications and why path is displayed as C:/fakepath. What I am trying to do is standard feature on every other website i.e. change users profile image. I am trying to implement that.
    – goryef
    Nov 11 at 17:15











  • @AlonEitan I think he wants to upload file from browser to server and save it's location in db.
    – num8er
    Nov 11 at 17:16










  • @goryef I would recommend You watch videos from here: youtube.com/… good luck (:
    – num8er
    Nov 11 at 17:19






  • 1




    @goryef I know nothing about node.js (I'm a PHP developer) but isn't this question good enough? If you're wondering about saving the image as BLOB in the DB or just the path then read this
    – Alon Eitan
    Nov 11 at 17:25














up vote
0
down vote

favorite












Looking for some guidance here. I am building Nodejs/Express app with MySQL Database. I want to be able to click on the users image on the web page (initial image is generic), select a different image and upload/save new image into MySQL database. I using:



$('#file-input').trigger('click').change (function()
alert($('#file-input').val());
)


I get C:/fakepath... for image location. I would like to how to upload/save selected image to the MySQL database. Connection to database is established, and routes for regular data work just fine.










share|improve this question























  • "I want to be able to click on the users image on the web page (initial image is generic), select a different image and upload/save new image into MySQL database" - You simply can not do it, you can't access to the local file system on behalf of the user, think about the security implications of having this type of feature
    – Alon Eitan
    Nov 11 at 17:09











  • I understand all security implications and why path is displayed as C:/fakepath. What I am trying to do is standard feature on every other website i.e. change users profile image. I am trying to implement that.
    – goryef
    Nov 11 at 17:15











  • @AlonEitan I think he wants to upload file from browser to server and save it's location in db.
    – num8er
    Nov 11 at 17:16










  • @goryef I would recommend You watch videos from here: youtube.com/… good luck (:
    – num8er
    Nov 11 at 17:19






  • 1




    @goryef I know nothing about node.js (I'm a PHP developer) but isn't this question good enough? If you're wondering about saving the image as BLOB in the DB or just the path then read this
    – Alon Eitan
    Nov 11 at 17:25












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Looking for some guidance here. I am building Nodejs/Express app with MySQL Database. I want to be able to click on the users image on the web page (initial image is generic), select a different image and upload/save new image into MySQL database. I using:



$('#file-input').trigger('click').change (function()
alert($('#file-input').val());
)


I get C:/fakepath... for image location. I would like to how to upload/save selected image to the MySQL database. Connection to database is established, and routes for regular data work just fine.










share|improve this question















Looking for some guidance here. I am building Nodejs/Express app with MySQL Database. I want to be able to click on the users image on the web page (initial image is generic), select a different image and upload/save new image into MySQL database. I using:



$('#file-input').trigger('click').change (function()
alert($('#file-input').val());
)


I get C:/fakepath... for image location. I would like to how to upload/save selected image to the MySQL database. Connection to database is established, and routes for regular data work just fine.







mysql node.js ajax express avatar






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 17:10









Alon Eitan

11.1k63652




11.1k63652










asked Nov 11 at 16:41









goryef

436




436











  • "I want to be able to click on the users image on the web page (initial image is generic), select a different image and upload/save new image into MySQL database" - You simply can not do it, you can't access to the local file system on behalf of the user, think about the security implications of having this type of feature
    – Alon Eitan
    Nov 11 at 17:09











  • I understand all security implications and why path is displayed as C:/fakepath. What I am trying to do is standard feature on every other website i.e. change users profile image. I am trying to implement that.
    – goryef
    Nov 11 at 17:15











  • @AlonEitan I think he wants to upload file from browser to server and save it's location in db.
    – num8er
    Nov 11 at 17:16










  • @goryef I would recommend You watch videos from here: youtube.com/… good luck (:
    – num8er
    Nov 11 at 17:19






  • 1




    @goryef I know nothing about node.js (I'm a PHP developer) but isn't this question good enough? If you're wondering about saving the image as BLOB in the DB or just the path then read this
    – Alon Eitan
    Nov 11 at 17:25
















  • "I want to be able to click on the users image on the web page (initial image is generic), select a different image and upload/save new image into MySQL database" - You simply can not do it, you can't access to the local file system on behalf of the user, think about the security implications of having this type of feature
    – Alon Eitan
    Nov 11 at 17:09











  • I understand all security implications and why path is displayed as C:/fakepath. What I am trying to do is standard feature on every other website i.e. change users profile image. I am trying to implement that.
    – goryef
    Nov 11 at 17:15











  • @AlonEitan I think he wants to upload file from browser to server and save it's location in db.
    – num8er
    Nov 11 at 17:16










  • @goryef I would recommend You watch videos from here: youtube.com/… good luck (:
    – num8er
    Nov 11 at 17:19






  • 1




    @goryef I know nothing about node.js (I'm a PHP developer) but isn't this question good enough? If you're wondering about saving the image as BLOB in the DB or just the path then read this
    – Alon Eitan
    Nov 11 at 17:25















"I want to be able to click on the users image on the web page (initial image is generic), select a different image and upload/save new image into MySQL database" - You simply can not do it, you can't access to the local file system on behalf of the user, think about the security implications of having this type of feature
– Alon Eitan
Nov 11 at 17:09





"I want to be able to click on the users image on the web page (initial image is generic), select a different image and upload/save new image into MySQL database" - You simply can not do it, you can't access to the local file system on behalf of the user, think about the security implications of having this type of feature
– Alon Eitan
Nov 11 at 17:09













I understand all security implications and why path is displayed as C:/fakepath. What I am trying to do is standard feature on every other website i.e. change users profile image. I am trying to implement that.
– goryef
Nov 11 at 17:15





I understand all security implications and why path is displayed as C:/fakepath. What I am trying to do is standard feature on every other website i.e. change users profile image. I am trying to implement that.
– goryef
Nov 11 at 17:15













@AlonEitan I think he wants to upload file from browser to server and save it's location in db.
– num8er
Nov 11 at 17:16




@AlonEitan I think he wants to upload file from browser to server and save it's location in db.
– num8er
Nov 11 at 17:16












@goryef I would recommend You watch videos from here: youtube.com/… good luck (:
– num8er
Nov 11 at 17:19




@goryef I would recommend You watch videos from here: youtube.com/… good luck (:
– num8er
Nov 11 at 17:19




1




1




@goryef I know nothing about node.js (I'm a PHP developer) but isn't this question good enough? If you're wondering about saving the image as BLOB in the DB or just the path then read this
– Alon Eitan
Nov 11 at 17:25




@goryef I know nothing about node.js (I'm a PHP developer) but isn't this question good enough? If you're wondering about saving the image as BLOB in the DB or just the path then read this
– Alon Eitan
Nov 11 at 17:25












1 Answer
1






active

oldest

votes

















up vote
2
down vote













Before answering your question will suggest you to not save image into your MySql or any database, use IPFS, local application directory/folder, or best AWS s3 bucket.



You can use busboy.js NPM module or multer.js NPM module for file upload to server, there's lots of good reason to not save any kind of file in local database.



Now back to how you can save image in database. You can do so by first converting your image to a data format your MySql understand. By default image is binary and depending upon image selected some image binary is so big that even MySql text datatype is small for them. Converting binary to hexadecimal does help but still too big for MySql text datatype. Also you will need multipart/form-data for file upload.



You can easily find "How to upload file in nodeJs?" in a google search. Still if need an example here's one "Upload file using multer.js"






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250897%2fnodejs-express-save-select-avatar-from-web-client-and-save-directly-to-mysql-dat%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    Before answering your question will suggest you to not save image into your MySql or any database, use IPFS, local application directory/folder, or best AWS s3 bucket.



    You can use busboy.js NPM module or multer.js NPM module for file upload to server, there's lots of good reason to not save any kind of file in local database.



    Now back to how you can save image in database. You can do so by first converting your image to a data format your MySql understand. By default image is binary and depending upon image selected some image binary is so big that even MySql text datatype is small for them. Converting binary to hexadecimal does help but still too big for MySql text datatype. Also you will need multipart/form-data for file upload.



    You can easily find "How to upload file in nodeJs?" in a google search. Still if need an example here's one "Upload file using multer.js"






    share|improve this answer
























      up vote
      2
      down vote













      Before answering your question will suggest you to not save image into your MySql or any database, use IPFS, local application directory/folder, or best AWS s3 bucket.



      You can use busboy.js NPM module or multer.js NPM module for file upload to server, there's lots of good reason to not save any kind of file in local database.



      Now back to how you can save image in database. You can do so by first converting your image to a data format your MySql understand. By default image is binary and depending upon image selected some image binary is so big that even MySql text datatype is small for them. Converting binary to hexadecimal does help but still too big for MySql text datatype. Also you will need multipart/form-data for file upload.



      You can easily find "How to upload file in nodeJs?" in a google search. Still if need an example here's one "Upload file using multer.js"






      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        Before answering your question will suggest you to not save image into your MySql or any database, use IPFS, local application directory/folder, or best AWS s3 bucket.



        You can use busboy.js NPM module or multer.js NPM module for file upload to server, there's lots of good reason to not save any kind of file in local database.



        Now back to how you can save image in database. You can do so by first converting your image to a data format your MySql understand. By default image is binary and depending upon image selected some image binary is so big that even MySql text datatype is small for them. Converting binary to hexadecimal does help but still too big for MySql text datatype. Also you will need multipart/form-data for file upload.



        You can easily find "How to upload file in nodeJs?" in a google search. Still if need an example here's one "Upload file using multer.js"






        share|improve this answer












        Before answering your question will suggest you to not save image into your MySql or any database, use IPFS, local application directory/folder, or best AWS s3 bucket.



        You can use busboy.js NPM module or multer.js NPM module for file upload to server, there's lots of good reason to not save any kind of file in local database.



        Now back to how you can save image in database. You can do so by first converting your image to a data format your MySql understand. By default image is binary and depending upon image selected some image binary is so big that even MySql text datatype is small for them. Converting binary to hexadecimal does help but still too big for MySql text datatype. Also you will need multipart/form-data for file upload.



        You can easily find "How to upload file in nodeJs?" in a google search. Still if need an example here's one "Upload file using multer.js"







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 18:41









        NAVIN

        1,5023622




        1,5023622



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250897%2fnodejs-express-save-select-avatar-from-web-client-and-save-directly-to-mysql-dat%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3