angularjs - Add HTTP Header in JavaScript to requests for images -


I have a JS / HTML project that is based on the angles where I secure the API with the authorization token set in the http header Keep me I now want to protect access to images from the server.

I know how to do this on the server side, but how can I add HTTP headers to image requests in angular or javascript? For API request we have already added it to the services ($ ressource) and it works.

in Kangaroo 1.2.X

There are more ways to do this. In Cooner 1.2, I advise to "clear" an "exiting requests" and add headers.

// An interceptor is just one service App.factory ('myInterceptor', function ($ q) {return} {requests outside requests Request: Function (Configuration) {var myDomain = "http://whatever.com"; // (Optional) If the request is heading towards your targeted domain, // add your header, otherwise it alone Skip (if config.url.indexOf (myDomain)! == -1) {// Authorization Header (or add custom headers)) here config.headers.Authorization = "Token 12309123019238";} Return Conversion;}}} );

Conneller 1.0.X

; by app.config (function ($ httpProvider) {// configuration $ HTTPProvider.interceptors.push ('myInterceptor';}); H3>

If you are using Kangaroo 1.0.X, you will have to set the header globally in the normal header ... $ http.defaults.headers.common.uthentication < / P>

Edit:

You will need to create an instruction for things to come from, and it will probably become weird.

You will need the following:

  1. A Create a directive that makes your tag tag, or
  2. $ http to request that instruction image. > Use the service (thus taking advantage of the above HTTP interceptor). For this you have to check the extension and set the appropriate content type headers, like something: $ http ({url: 'images / Foo.jpg ', header: {' content-type ':' image / jpeg '}). Then (...)
  3. When you receive a response, you get raw base64 date And the src attribute, like: like the data code / ol>

    ... so that they will go crazy.

    If you can create it then your server does not protect images that are better for you.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -