0

I am uploading files using spring boot and angular JS , I am also adding the details of the files to a table where i want to have access to the file , so i put in the html page

<tr ng-repeat="r in reports"  >

                                <td>{{r.id_file}}</td>
                                <td>{{r.nameOfUploader}}</td>
                                <td>{{r.dateOfUpload}}</td>
                                <td>{{r.typeOfFile}}</td>
<!--                                <td>{{r.fileName}}</td> -->
    <td><a ng-href="F:/FilesStore/{{r.id_file}}-{{r.nameOfUploader}}"/>{{r.fileName}}</a></td>

Any ideas?

Chris Barr
  • 29,851
  • 23
  • 95
  • 135
Hajar Ch
  • 39
  • 3
  • 13
  • 2
    You need a URL that is relative to your document root. From the browser you do not have access to the drive on the server, only to the content of document root. So it cannot find F:/ – Vincent Ramdhanie Jun 11 '15 at 17:38
  • 1
    You can't link to the hard drive as you've done. You need to link to the path relative to the webserver. If your webserver runs as `localhost` then the ng-href should be `localhost/path_to_file` – soote Jun 11 '15 at 17:38
  • As far as I know this could be possible with the Web FileSystem API. – LordTribual Jun 11 '15 at 17:39
  • But when i upload the files, i store them in f:/fileStore , sso howa can i change my url? – Hajar Ch Jun 11 '15 at 17:40
  • `file:///` will do the trick... – Jossef Harush Kadouri Jun 11 '15 at 17:40
  • Sorry but it doesn't work – Hajar Ch Jun 11 '15 at 17:45
  • I wanted to downoald my files on server as you tell me and i added a folder wich name is FilesStore in the folder static and i put in the java controller BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File("/FilesStore/"+d2.getFileName()))); but it gives me an error , what's wrong? – Hajar Ch Jun 13 '15 at 07:40

1 Answers1

1

Store your files on a server

As some posted in the comments, from the browser you do not have access to the files on the server and to access these files you will need to "proxy" them - serve these files as static files from your web application server

e.g.

HTTP GET /static/storage/<filename>

will be retrieved from

F:/FilesStore/<filename>

and your link will look like

<a ng-href="/static/storage/{{r.id_file}}-{{r.nameOfUploader}}" />

If you still want to link to direct files

i guess it's become more relevant if you and your co-workers have the same share mapping (lan-office network), then (for internal use of course) you can add file:/// to the path which will result in opening it via the browser

<a ng-href="file:///F:/FilesStore/{{r.id_file}}-{{r.nameOfUploader}}" />
Jossef Harush Kadouri
  • 32,361
  • 10
  • 130
  • 129