简体   繁体   English

如何在本地提供文件?

[英]How to serve files locally?

In my Angular directive, I'm trying to get the path to another folder outside of the project, that contains a bunch of files. 在我的Angular指令中,我试图获取项目外的另一个文件夹的路径,该文件夹包含一堆文件。 The idea is to join that path with the list of files existent and draw them using the omnivore library (It is not important here, but I'll leave the code for some context): 想法是将该路径与存在的文件列表连接在一起,并使用omnivore库绘制它们(这里并不重要,但是我将代码留给某些上下文):

  var folderPath = "../../../traceMySteps-backend/MyTracks/ProcessedTracks/";

 return {

        restrict: 'E',
        scope: true,
        link: function($scope, $elem, $attr, $http) {

              for (var i = 0; i < jsonRes.length; i += 1) {
                console.log(folderPath + jsonRes[i])
                omnivore.gpx(folderPath + jsonRes[i]).addTo(trackmaps[trackmapCount]);
              }

...

The problem is that Angular thinks the folder is on the localhost: http://localhost:8000/traceMySteps-backend/MyTracks/ProcessedTracks/2016-05-04-‌​part1.gpx when the folder is outside this Angular project 问题是当文件夹位于Angular项目之外时,Angular认为该文件夹位于本地主机上: http://localhost:8000/traceMySteps-backend/MyTracks/ProcessedTracks/2016-05-04-‌​part1.gpx

The folder structure is: 文件夹结构为:

Backend_folder/MyTracks/ProcessedTracks/
Angular_Project/app/js/directives/file

Backend_folder and Angular_Project are at the same level (both inside one folder). Backend_folderAngular_Project处于同一级别(都在一个文件夹中)。 And in that file is where that directive code is. 指令代码在该file中。 I need to access ProcessedTracks/ from it. 我需要从中访问ProcessedTracks/ Is there any way? 有什么办法吗? This relative path does not work and I've also tried the absolute path, but the error is the same. 该相对路径不起作用,我也尝试了绝对路径,但是错误是相同的。

This is not possible as the client (browser) doesn't have access to directory structure as this is a security risk. 由于客户端(浏览器)无权访问目录结构,因此这是不可能的,因为这存在安全风险。 I think you can do this by installing some 3rd party tools on the server or exposing your files via a web service. 我认为您可以通过在服务器上安装一些第三方工具或通过Web服务公开文件来做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM