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?
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
add a comment |
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
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
add a comment |
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
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
javascript node.js reactjs
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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.
add a comment |
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
add a comment |
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered 2 days ago
virtusmaiorvirtusmaior
233
233
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered 2 days ago
jenil christojenil christo
156112
156112
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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