5

I get local directories for images in a csv file and the task is to upload them to a server with an api that deals with files or blobs ... so I need to convert those local directories to files or blobs (example: C:\folder\file).

I thought this is a common case that wouldn't take much time to dig up a solution for but it turned out to be a little bid of a confusion or maybe I am not yet really that flexible with JavaScript.

I tried this:

var file = File.createFromFileName("path/to/file");

based on the documentation (here)

I get : File.createFromFileName is not a function The test is conducted on firefox.

Ahmed Samy
  • 1,006
  • 2
  • 11
  • 24
  • https://developer.mozilla.org/en-US/docs/Web/API/Blob ? – Roko C. Buljan Jan 30 '18 at 00:06
  • Sounds like you want to use a Server Language. – StackSlave Jan 30 '18 at 00:19
  • the file paths that you have in your `CSV` files are under a web accessible directory? or are you free to place those files there? what format is of the file paths in the `csv` file? – Muhammad Omer Aslam Jan 30 '18 at 00:37
  • Where exactly are you running this from in Firefox? From the documentation you linked to: "This only works from privileged code, so web content can't do it." – AuxTaco Jan 30 '18 at 00:57
  • @MuhammadOmerAslam the paths are put manually by the user in the csv file and they are punch of images. – Ahmed Samy Jan 30 '18 at 01:25
  • what i am asking is are they accessible like `localhost/somdir/images/image1.png` – Muhammad Omer Aslam Jan 30 '18 at 01:26
  • @AuxTaco I am running this locally. I guess the documentation is not what I am looking for then. – Ahmed Samy Jan 30 '18 at 01:26
  • @MuhammadOmerAslam The are locally saved in the machine where the user fills the csv file. i.e, "F:\\folder\file" – Ahmed Samy Jan 30 '18 at 01:28
  • hmm so , they are absolute paths to the file – Muhammad Omer Aslam Jan 30 '18 at 01:28
  • question updated – Ahmed Samy Jan 30 '18 at 01:32
  • 1
    So the javascript is ran from a normal html page? You simply can't, for obvious security reasons (Would you like any website be able to read all the content of your computer?). What you linked to is part of privileged `chrome://` API (i.e browser extensions). If you are not writing such an extension, this won't help you. – Kaiido Jan 30 '18 at 01:46
  • @Kaiido with my permission yes. The thing is. The website that I am building is like a control panel for a mobile application where the app admin uses excel sheets to upload data into the database so it can be reflected in the app. The data sometimes includes images saved in his/her local machine – Ahmed Samy Jan 30 '18 at 08:15

0 Answers0