0

I have a JSON

MyJson = {name:"file1",path:"d://photos/photo.jpg"}

I want to get photo.jpg in a const variable

const file: File = MyJson.path;

How can I do this using Angular or Javascript? This is not a duplicate of How to read text file please don't close. I want to read this file as dataUrl.

yog
  • 199
  • 1
  • 2
  • 20
  • Why this question is closed? I already tried the solution given in the link. It works for text files, not for image files. I want to read an image file. – yog Jan 11 '22 at 07:25
  • 1
    It's not the best duplicate target, but it does apply (particularly [this answer](https://stackoverflow.com/a/28610354/157247)) **if** you can do it at all. But you probably can't do it at all. If you're doing this from a page loaded via `http:` or `https:`, you **cannot** read local files with paths you specific in your code, for obvious security reasons. The user has to provide the file to you (via an `input type="file"` or drag-and-drop, etc.). – T.J. Crowder Jan 11 '22 at 08:55
  • Thanks for your answer T.J. I wanted some answer rather than downvote or duplicate.I will try to find other way – yog Jan 11 '22 at 08:58
  • 1
    There's no point in people writing duplicate answers to duplicate questions. The answers already exist. They aren't going to change just because you don't like them. JavaScript can't give the browser a file path to a file on the user's computer and have it read it into the website — that would be a huge security problem. – Quentin Jan 11 '22 at 09:03
  • 1
    Thanks for helping the newbie guys. I am learning. :) – yog Jan 11 '22 at 09:09

0 Answers0