Getting File Path - javascript

I recently made a Python app where I take an Excel file, convert it to a CSV file, and then shoot it out with an Email. I tried turning this application into a Web App and here is where issues arose. In order to send the a file using Email, I need to get the full file path and I am not sure how to get it. In order to let the user pick out the file, I used <input type="file">, but this only supplies me with the name of the file and not the actual file path. Any suggests on what I should do to fix this issue?

Use the os module in python.
import os
os.path.abspath('/path/to/file')

Related

Search through files in path using only javascript

I'm coding a webpage that needs to read some data from different csv on a path depending on the country of the user.
the path is something like this:
./csv/m2-2022-10-25_13_45_55_es.csv
m2-2022-10-25_13_45_56_fr.csv
m2-2022-10-25_13_46_04_it.csv
etc
And those files will be replaced regularly, the only that we'll always have is the country code (es, fr, it, etc).
So, what I need is to list all the files on the path to an array, and loop through the array to find if the last characters of the filename are $countryCode + ".csv", and there run some code.
But I can't find how, all the solutions I find are using Node.js, but are there a solution using only Javascript (or jQuery)?
Regards!
You cannot use pure Javascript to do that, because if you wanted to search files in your computer only using javascript, it would be a huge security breach.
You must use node.js to open files but you can make an API to your nodejs file from your javascript and you can send as a response the content of your file.
Here some links that might help you :
FS : https://nodejs.org/api/fs.html
NodeJS api : https://medium.com/swlh/how-to-create-a-simple-restful-api-in-node-js-ae4bfddea158
You can check a similar question here:
Get list of filenames in folder with Javascript
You can't access to filesystem from the frontend, this it would be a huge security breach, because anyone could access to your filesystem tree.
You have to do a function in backend to build the array you want and send it to frontend.
If you create a function in backend file that returns the array of files in the folder, you can call it from the frontend via XMLHttpRequest or Fetch to get the array in frontend and be able to use in your js file.

file download in react application

I am trying to understand download facility in reactjs. actually first I am uploading one file using reactjs. so for that I have given file upload path and it will return one url in return in the database. so for ex if I am uploading one file it is returning one url.
in my env file I have given this location UPLOAD_LOCATION="C:\Users\SS2345\Desktop\shruti" .as of now I am giving location of my local machine.
in database for this file a path will be saved.
for ex "localhost:3000/api/4f3ce528-7c99-4516-9ccf-95d8d0be74a2.docx" file name has been generated due to some algorithm and my api is running on localhost:3000/api path. file is located on this path. C:\Users\SS2345\Desktop\shruti
how can I use it to download. I am writing below.
<div >
<a href="http://localhost:3000/api/certificates/uploads/8373f87f-9a28-4c1b-a80b-8038fe990e96.docx" download>File Download</a>
</div>
I am getting error.
?
what step I need to do to achieve it?

Export custom file to disk via Excel Add-in?

I'm new to Excel Web Add-Ins and want to figure out if it's possible to make an add-in that can export a custom file.
I've looked around and all I find are Excel specific commands like Workbook.SaveAs() but I can't find anything on making custom export functions. I need to convert the file into XML but a specific XML setup and so, I could just work the data before I save it to XML. But again, can't find much of anything to suggest that this is supported.
How would I go about writing a file to disk from Excel that isn't just the Workbook?
There's no such API to support exporting custom file to disk. It seems we can have workaround to do this work, this workaround just works for excel online.
Please see this link:
How to create a file in memory for user to download, but not through server?
The closest thing there is for what you want to do is:
Office.context.document.getFileAsync(Office.FileType.Compressed, (result) => {
const file = result.value;
// do whatever ...
});
The file variable in this case contains the entire document in Office Open XML (OOXML) format as a byte array.

How to select destination for output AngularJS/Node.js

I have an application built with AngularJS and node.js that takes in a csv file, does some work on it and then outputs it.
Currently the only way I can output it is:
<a download="fileName.csv" ng-href="{{file}}">fileName.csv</a>"
But this will always put it in the 'Downloads' folder. Is there a way to ask for the destination and use that to output the file?
AFAIK There's no way to pick where the file ends up on the client machine, that's determined by their browser. It's going to your downloads folder because that's the default location.

Error When Saving as Binary in ExtendScript

I am trying to save a script as binary in extendscript so a client cannot view our code but I am running into an issue. Hopefully someone here knows a workaround.
In my script I have it calling to include an outside data file to pull informational values the script needs;
#include "/Users/GratefullyDyed/Sublimation/data.js";
Now I need to change that file path to the path that will be on my clients computer. When I do that and try to save as binary I get an error that "file path does not exist", because the file path is on their computer and not mine.
Is there a simple way around this I am missing?
Thanks!

Categories

Resources