Retrieve Absolute File Path With JavascriptCreate GUID / UUID in JavaScript?How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?

Approximating irrational number to rational number

How can "mimic phobia" be cured or prevented?

Pre-mixing cryogenic fuels and using only one fuel tank

Store Credit Card Information in Password Manager?

Is it possible to have a strip of cold climate in the middle of a planet?

Why should universal income be universal?

Why did the Mercure fail?

Create all possible words using a set or letters

Why do compilers behave differently when static_cast(ing) a function to void*?

Delivering sarcasm

How to bake one texture for one mesh with multiple textures blender 2.8

Fear of getting stuck on one programming language / technology that is not used in my country

A social experiment. What is the worst that can happen?

Problem with TransformedDistribution

Why Shazam when there is already Superman?

Why electric field inside a cavity of a non-conducting sphere not zero?

Open a doc from terminal, but not by its name

When were female captains banned from Starfleet?

Yosemite Fire Rings - What to Expect?

Creature in Shazam mid-credits scene?

Is it improper etiquette to ask your opponent what his/her rating is before the game?

Melting point of aspirin, contradicting sources

Longest common substring in linear time

Creepy dinosaur pc game identification



Retrieve Absolute File Path With Javascript


Create GUID / UUID in JavaScript?How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?













0















Lets say you have a web application that uses NodeJS and ReactJS. Both are working on your local machine. NodeJS is accepting some files that are selected from ReactJS GUI with a simple file upload. Like this :



<input type="file" id="fileUploaderInput" ref="fileUploader"/>



You want to pass this file to your NodeJS so that it will perform some big data operations. However, since the Browsers does not have the access to client's File System, you can not take the absolute path of the file selected. Hence you can not inform your NodeJS server about the file. What should be the best approach for this?



I tried reading the file with react and then write it to a path where NodeJS already knows, but it does not seem to me as a best approach.










share|improve this question






















  • Why do you need the absolute file path to upload a file to server?

    – jenil christo
    2 days ago







  • 1





    "Both are working on your local machine" If that’s always the case, why not build a desktop app with e.g. Electron?

    – idmean
    2 days ago












  • @jenilchristo Hi, there is no listener in my NodeJS that waits for a file. And I could not decide if it should since my app will always work on local machine with NodeJS and ReactJS. I just need absolue path of the file that lies in somewhere that NodeJS can read with simple var fs = require('fs');

    – I.K.
    2 days ago











  • @idmean Hi, thank you, I looked it up and this may be a good solution for my case. But still curious if there exists a simple way to achieve this without losing browser support.

    – I.K.
    2 days ago











  • if you do persist in web app, say your back-end framework (ExpressJS/AdonisJS/...)

    – Gaspar
    2 days ago















0















Lets say you have a web application that uses NodeJS and ReactJS. Both are working on your local machine. NodeJS is accepting some files that are selected from ReactJS GUI with a simple file upload. Like this :



<input type="file" id="fileUploaderInput" ref="fileUploader"/>



You want to pass this file to your NodeJS so that it will perform some big data operations. However, since the Browsers does not have the access to client's File System, you can not take the absolute path of the file selected. Hence you can not inform your NodeJS server about the file. What should be the best approach for this?



I tried reading the file with react and then write it to a path where NodeJS already knows, but it does not seem to me as a best approach.










share|improve this question






















  • Why do you need the absolute file path to upload a file to server?

    – jenil christo
    2 days ago







  • 1





    "Both are working on your local machine" If that’s always the case, why not build a desktop app with e.g. Electron?

    – idmean
    2 days ago












  • @jenilchristo Hi, there is no listener in my NodeJS that waits for a file. And I could not decide if it should since my app will always work on local machine with NodeJS and ReactJS. I just need absolue path of the file that lies in somewhere that NodeJS can read with simple var fs = require('fs');

    – I.K.
    2 days ago











  • @idmean Hi, thank you, I looked it up and this may be a good solution for my case. But still curious if there exists a simple way to achieve this without losing browser support.

    – I.K.
    2 days ago











  • if you do persist in web app, say your back-end framework (ExpressJS/AdonisJS/...)

    – Gaspar
    2 days ago













0












0








0








Lets say you have a web application that uses NodeJS and ReactJS. Both are working on your local machine. NodeJS is accepting some files that are selected from ReactJS GUI with a simple file upload. Like this :



<input type="file" id="fileUploaderInput" ref="fileUploader"/>



You want to pass this file to your NodeJS so that it will perform some big data operations. However, since the Browsers does not have the access to client's File System, you can not take the absolute path of the file selected. Hence you can not inform your NodeJS server about the file. What should be the best approach for this?



I tried reading the file with react and then write it to a path where NodeJS already knows, but it does not seem to me as a best approach.










share|improve this question














Lets say you have a web application that uses NodeJS and ReactJS. Both are working on your local machine. NodeJS is accepting some files that are selected from ReactJS GUI with a simple file upload. Like this :



<input type="file" id="fileUploaderInput" ref="fileUploader"/>



You want to pass this file to your NodeJS so that it will perform some big data operations. However, since the Browsers does not have the access to client's File System, you can not take the absolute path of the file selected. Hence you can not inform your NodeJS server about the file. What should be the best approach for this?



I tried reading the file with react and then write it to a path where NodeJS already knows, but it does not seem to me as a best approach.







javascript node.js reactjs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









I.K.I.K.

407




407












  • Why do you need the absolute file path to upload a file to server?

    – jenil christo
    2 days ago







  • 1





    "Both are working on your local machine" If that’s always the case, why not build a desktop app with e.g. Electron?

    – idmean
    2 days ago












  • @jenilchristo Hi, there is no listener in my NodeJS that waits for a file. And I could not decide if it should since my app will always work on local machine with NodeJS and ReactJS. I just need absolue path of the file that lies in somewhere that NodeJS can read with simple var fs = require('fs');

    – I.K.
    2 days ago











  • @idmean Hi, thank you, I looked it up and this may be a good solution for my case. But still curious if there exists a simple way to achieve this without losing browser support.

    – I.K.
    2 days ago











  • if you do persist in web app, say your back-end framework (ExpressJS/AdonisJS/...)

    – Gaspar
    2 days ago

















  • Why do you need the absolute file path to upload a file to server?

    – jenil christo
    2 days ago







  • 1





    "Both are working on your local machine" If that’s always the case, why not build a desktop app with e.g. Electron?

    – idmean
    2 days ago












  • @jenilchristo Hi, there is no listener in my NodeJS that waits for a file. And I could not decide if it should since my app will always work on local machine with NodeJS and ReactJS. I just need absolue path of the file that lies in somewhere that NodeJS can read with simple var fs = require('fs');

    – I.K.
    2 days ago











  • @idmean Hi, thank you, I looked it up and this may be a good solution for my case. But still curious if there exists a simple way to achieve this without losing browser support.

    – I.K.
    2 days ago











  • if you do persist in web app, say your back-end framework (ExpressJS/AdonisJS/...)

    – Gaspar
    2 days ago
















Why do you need the absolute file path to upload a file to server?

– jenil christo
2 days ago






Why do you need the absolute file path to upload a file to server?

– jenil christo
2 days ago





1




1





"Both are working on your local machine" If that’s always the case, why not build a desktop app with e.g. Electron?

– idmean
2 days ago






"Both are working on your local machine" If that’s always the case, why not build a desktop app with e.g. Electron?

– idmean
2 days ago














@jenilchristo Hi, there is no listener in my NodeJS that waits for a file. And I could not decide if it should since my app will always work on local machine with NodeJS and ReactJS. I just need absolue path of the file that lies in somewhere that NodeJS can read with simple var fs = require('fs');

– I.K.
2 days ago





@jenilchristo Hi, there is no listener in my NodeJS that waits for a file. And I could not decide if it should since my app will always work on local machine with NodeJS and ReactJS. I just need absolue path of the file that lies in somewhere that NodeJS can read with simple var fs = require('fs');

– I.K.
2 days ago













@idmean Hi, thank you, I looked it up and this may be a good solution for my case. But still curious if there exists a simple way to achieve this without losing browser support.

– I.K.
2 days ago





@idmean Hi, thank you, I looked it up and this may be a good solution for my case. But still curious if there exists a simple way to achieve this without losing browser support.

– I.K.
2 days ago













if you do persist in web app, say your back-end framework (ExpressJS/AdonisJS/...)

– Gaspar
2 days ago





if you do persist in web app, say your back-end framework (ExpressJS/AdonisJS/...)

– Gaspar
2 days ago












3 Answers
3






active

oldest

votes


















1














If your app will always be sitting on your local machine, a desktop app via electron will be a valid approach (as idmean noticed). There you can use the nodejs module fs to work with files even in the frontend, which is enabled via inter-process-communication to the backend.
If otherwise the nodejs-server will be sitting in the internet in the future, uploading the file and saving it via the nodejs-server is probably the best approach.






share|improve this answer






























    0














    It is not posible for a browser to get the absolute url of a file uploaded.This would be a security violation .



    So you cannot send the absolute file path and read it via fs in node. You can either pass the base64 from client and handle file upload in Node.js or use desktop alternative like Electron.



    If your app always runs in local you can also make the download folder predefined say for example (C:/Downloads)in Node.js and always upload files from the same folder, sending the filename from client.So if you select a file with name a.jpg,your Node.js code in local can use the fs to read from path C:/Downloads/a.jpg






    share|improve this answer






























      0














      It's quite simple. When you upload a file like



      <input type="file" />


      You get a file blob, you can send this blob to the server using rest API or parse data and then can pass this data to the server.






      share|improve this answer

























      • Can you expand your answer please? What does it mean "upload a file using tag"? An example would be great!

        – I.K.
        2 days ago










      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',
      autoActivateHeartbeat: false,
      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%2f55281027%2fretrieve-absolute-file-path-with-javascript%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      If your app will always be sitting on your local machine, a desktop app via electron will be a valid approach (as idmean noticed). There you can use the nodejs module fs to work with files even in the frontend, which is enabled via inter-process-communication to the backend.
      If otherwise the nodejs-server will be sitting in the internet in the future, uploading the file and saving it via the nodejs-server is probably the best approach.






      share|improve this answer



























        1














        If your app will always be sitting on your local machine, a desktop app via electron will be a valid approach (as idmean noticed). There you can use the nodejs module fs to work with files even in the frontend, which is enabled via inter-process-communication to the backend.
        If otherwise the nodejs-server will be sitting in the internet in the future, uploading the file and saving it via the nodejs-server is probably the best approach.






        share|improve this answer

























          1












          1








          1







          If your app will always be sitting on your local machine, a desktop app via electron will be a valid approach (as idmean noticed). There you can use the nodejs module fs to work with files even in the frontend, which is enabled via inter-process-communication to the backend.
          If otherwise the nodejs-server will be sitting in the internet in the future, uploading the file and saving it via the nodejs-server is probably the best approach.






          share|improve this answer













          If your app will always be sitting on your local machine, a desktop app via electron will be a valid approach (as idmean noticed). There you can use the nodejs module fs to work with files even in the frontend, which is enabled via inter-process-communication to the backend.
          If otherwise the nodejs-server will be sitting in the internet in the future, uploading the file and saving it via the nodejs-server is probably the best approach.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          virtusmaiorvirtusmaior

          233




          233























              0














              It is not posible for a browser to get the absolute url of a file uploaded.This would be a security violation .



              So you cannot send the absolute file path and read it via fs in node. You can either pass the base64 from client and handle file upload in Node.js or use desktop alternative like Electron.



              If your app always runs in local you can also make the download folder predefined say for example (C:/Downloads)in Node.js and always upload files from the same folder, sending the filename from client.So if you select a file with name a.jpg,your Node.js code in local can use the fs to read from path C:/Downloads/a.jpg






              share|improve this answer



























                0














                It is not posible for a browser to get the absolute url of a file uploaded.This would be a security violation .



                So you cannot send the absolute file path and read it via fs in node. You can either pass the base64 from client and handle file upload in Node.js or use desktop alternative like Electron.



                If your app always runs in local you can also make the download folder predefined say for example (C:/Downloads)in Node.js and always upload files from the same folder, sending the filename from client.So if you select a file with name a.jpg,your Node.js code in local can use the fs to read from path C:/Downloads/a.jpg






                share|improve this answer

























                  0












                  0








                  0







                  It is not posible for a browser to get the absolute url of a file uploaded.This would be a security violation .



                  So you cannot send the absolute file path and read it via fs in node. You can either pass the base64 from client and handle file upload in Node.js or use desktop alternative like Electron.



                  If your app always runs in local you can also make the download folder predefined say for example (C:/Downloads)in Node.js and always upload files from the same folder, sending the filename from client.So if you select a file with name a.jpg,your Node.js code in local can use the fs to read from path C:/Downloads/a.jpg






                  share|improve this answer













                  It is not posible for a browser to get the absolute url of a file uploaded.This would be a security violation .



                  So you cannot send the absolute file path and read it via fs in node. You can either pass the base64 from client and handle file upload in Node.js or use desktop alternative like Electron.



                  If your app always runs in local you can also make the download folder predefined say for example (C:/Downloads)in Node.js and always upload files from the same folder, sending the filename from client.So if you select a file with name a.jpg,your Node.js code in local can use the fs to read from path C:/Downloads/a.jpg







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 2 days ago









                  jenil christojenil christo

                  156112




                  156112





















                      0














                      It's quite simple. When you upload a file like



                      <input type="file" />


                      You get a file blob, you can send this blob to the server using rest API or parse data and then can pass this data to the server.






                      share|improve this answer

























                      • Can you expand your answer please? What does it mean "upload a file using tag"? An example would be great!

                        – I.K.
                        2 days ago















                      0














                      It's quite simple. When you upload a file like



                      <input type="file" />


                      You get a file blob, you can send this blob to the server using rest API or parse data and then can pass this data to the server.






                      share|improve this answer

























                      • Can you expand your answer please? What does it mean "upload a file using tag"? An example would be great!

                        – I.K.
                        2 days ago













                      0












                      0








                      0







                      It's quite simple. When you upload a file like



                      <input type="file" />


                      You get a file blob, you can send this blob to the server using rest API or parse data and then can pass this data to the server.






                      share|improve this answer















                      It's quite simple. When you upload a file like



                      <input type="file" />


                      You get a file blob, you can send this blob to the server using rest API or parse data and then can pass this data to the server.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 2 days ago

























                      answered 2 days ago









                      Rahul RanaRahul Rana

                      1444




                      1444












                      • Can you expand your answer please? What does it mean "upload a file using tag"? An example would be great!

                        – I.K.
                        2 days ago

















                      • Can you expand your answer please? What does it mean "upload a file using tag"? An example would be great!

                        – I.K.
                        2 days ago
















                      Can you expand your answer please? What does it mean "upload a file using tag"? An example would be great!

                      – I.K.
                      2 days ago





                      Can you expand your answer please? What does it mean "upload a file using tag"? An example would be great!

                      – I.K.
                      2 days ago

















                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281027%2fretrieve-absolute-file-path-with-javascript%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







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript