javascript - Serve files in img src using HTTP.get -


my file can served if add x-authentication token header of "get" http request (and don't want use cookie). direct consequence can not call file using url in html, need javascript call, asynchronous preferably.

since client meteor, want use http.get method. part obtain file http.get, not 1 attach to, example, src attribute of image.

how should return result of file download if want use in page? (e.g.attach src attribute of image). should use dedicated template or can achieved using helper?

edit: made progress. based on answers similar case "how display images downloaded using xmlhttprequest, have seen can encode in base64 response content text.

so here thinking: use helper return img src attribute. know http call asynch when use client-side return placeholder value default (see last line)

here code (the helper called inside img src attribute):

    link : function(){      http.get ("http://localhost:3000" + files.baseurl + "/" + this.md5,     {         headers:{             "x-auth-token": accounts._storedlogintoken()         }         },         function (error, result) {             if (error){                 console.log ("an error " + result.statuscode + " occured");             }             else             {                 retval ="";                         (var i=0; i<=result.content.length-1; i++)                         retval += string.fromcharcode(result.content.charcodeat(i) & 0xff);                 return "data:"+this.contenttype+";base64," + encode64(retval)             }         })     return "http://localhost:3000/images/placeholder.png"     }, 

this code doesn't work, it's throwing error on http.get line. "exception in template helper: .link@http://localhost:3000/client/views/uploader/uploader.js?b82cf5a1d421ef6a5a1e4eabaf8327fd1a9f2d75:43:2"

as bravekenny advised, used chrome instead of firefox debug. appeared http package missing.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -