How to work with the file:// and Angular protocol

Asked

Viewed 202 times

2

I was wondering if it is possible to work with an Http:// request locally in my application and not on a local server, if possible how do I do this? (does not necessarily have to be with the file protocol://).

//Cleanup the popover when we're done with it!
  $scope.$on('$destroy', function() {
    $scope.musicActionspopover.remove();
  });

  $scope.openMusicActions = function($event, music) {
    $scope.audioSelected = music;
    $scope.musicActionspopover.show($event);
  };

  $scope.closeMusicActionsPopover = function() {
    $scope.musicActionspopover.hide();
  };

  $scope.playAudio = function($event, audioSelected) {
    // Prevents start the song when it is clicked on the menu
    if ($event.srcElement.tagName == 'I') {
      $event.preventDefault();
      return;
    }

    var audioSelectedIndex = 0;
    var queueMusics = [];

    angular.forEach($scope.playlist.audios, function (music, index) {
      if (audioSelected.nid == music.nid) {
        audioSelectedIndex = index;
      };

        queueMusics.push({
        id: music.nid, 
        name: music.title, 
        artist: music.interpeters[0], 
        audioUrl: "file://audio/0379442681742547b1cc4baacab409c3/320/ts_.m3u8",//music.audio_url, 
        albumId: music.album.nid, 
        albumCover: music.album.cover, 
        albumBlurCover: music.album.blur_cover, 
        audioType: music.audioType,
        collectionSourceID: $scope.playlist.nid,
        collectionSourceTitle: $scope.playlist.title,
        collectionSourceCategory: "System Playlist"
      });
    });

    $rootScope.$emit("playAudio", {index: audioSelectedIndex, queueName: $scope.playlist.title, audios: queueMusics});
    $scope.closeMusicActionsPopover();
  };
  $scope.playSystemPlaylist = function ($event) {

    playlist = $scope.playlist;
    var audioSelectedIndex = 0;
    var queueMusics = [];

    angular.forEach(playlist.audios, function (music, index) {
      queueMusics.push({
        id: music.nid, 
        name: music.title, 
        artist: music.interpeters[0], 
        audioUrl: music.audio_url, 
        albumId: music.album.nid, 
        albumCover: music.album.cover, 
        albumBlurCover: music.album.blur_cover,
        audioType: music.audioType,
        collectionSourceID: $scope.playlist.nid,
        collectionSourceTitle: $scope.playlist.title,
        collectionSourceCategory: "System Playlist"
      });
    });

    $rootScope.$emit("playAudio", {index: audioSelectedIndex, queueName: playlist.title, audios: queueMusics});
  };

}]);

Currently I have this mistake :

clappr.js:30025 Xmlhttprequest cannot load file:/audio/0379442681742547b1cc4baacab409c3/320/ts_.m3u8. Cross origin requests are only supported for Protocol schemes: http, data, Chrome, Chrome-Extension, https. loadInternal @clappr.js:30025 d @Raven.js:1279

  • Good answering the question directly, yes but it is interesting that you put more language information and the like so we can answer in a more accurate way.

  • I have an angular application, which works with stream hls, there is a way to make these requests locally ?

  • I don’t know if I understand the question so I won’t publish it as an answer... but I think what you want is to access a local site by browser, right? http://localhost/ and http://127.0.0.1/ meet almost every case (if not answer is because the local address of your computer has been reconfigured).

  • On-premises or cloud application ?

  • @Renan I’m thinking, correct me if I’m wrong, that the application is in the cloud but he wants to use some local requests

  • @Otto I don’t understand the question and I don’t know if that’s it. I think your first comment was the best, this question can be closed because it is not clear enough if more details are not included.

  • the application would be nothing more than a music stream similar to Spotify, so I want to make him make this request for the songs that are on the server locally;

  • Yes yes I am also waiting for an answer so we have plausible information to answer

  • Look hasn’t helped as much, but yes it has of course, you running a local http server like "xampp" something so you will have clear access.

  • @Lucasinacio when putting codes, make an edit on your ask and add it

  • now I think it looks better

  • I noticed that used the android tag, you are then using webView?

Show 7 more comments

2 answers

1

Simple answer: You can’t.

The protocol file:// has several restrictions imposed by the browser.

However nothing prevents you from creating a web service on your machine, and offer a local site accessible by a URL similar to http://localhost.

Some examples of simple http server implementation below:

  • Python - python -m SimpleHTTPServer 8080
  • PHP - php -S localhost:8080
  • Nodejs - npm install -g http-server, followed by http-server
  • has another protocol or request you can use offline, remembering that I want to work locally on the application and not on a local server.

1

The problem is safety.

clappr.js:30025 Xmlhttprequest cannot load file:/audio/0379442681742547b1cc4baacab409c3/320/ts_.m3u8. Cross origin requests are only supported for Protocol schemes: http, data, Chrome, Chrome-Extension, https. loadInternal @ clappr.js:30025 d @Raven.js:1279

What happened here is that a page tried to access something outside of its domain, over a protocol in which this is not possible (the supported protocols are listed in the error message).

You must use one of the specified protocols. Also, you will probably need to configure the application or server to allow unsafe requests. And will have a large margin for security holes in the application.

Perhaps it is the case to rethink the architecture of the application and how its content will be served. I suggest opening a specific question on how to avoid requests Cross origin in your application, when you hold both the page making the request and the content to be served on the same machine. So you can do what you have to do with less code, less settings, and your application will be safer.

  • I believe you asked the wrong way, I’ll rephrase the question so you can help me better.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.