javascript - Prompt file download -


i have link on page on click of trying generate pdf document , show open - save prompt on browser.

my html (reactjs component) has below code onclick calls _getmydocument function calls webapi method.

 <div classname="row">      <a href="#" onclick={this._getmydocument.bind(this)}>test link</a>  </div>    _getmydocument(e) {             getmydocument(this.props.mydata).then(()=> {    }).catch(error=> {    }); 

my controller has below code

[httppost] [route("generate/report")] public ihttpactionresult getmyreport(mydata mydata)  {       byte[] mydoc = mybusinessobject.generatemyreport(mydata);     var result = new httpresponsemessage(httpstatuscode.ok)         {             content = new bytearraycontent(mydoc)         };         result.content.headers.contentdisposition =             new contentdispositionheadervalue("attachment")             {                 filename = "mydocument.pdf"             };         result.content.headers.contenttype =             new mediatypeheadervalue("application/octet-stream");          var response = responsemessage(result);          return response;   } 

currently code executes don't file pdf download prompt. doing wrong here?

response object on success ajax call lokks below

enter image description here

your response server looks good. missing part not handling response client side in correct way.

lets assume resource url object looks below in js. (i.e. know resource url, if dont know yet, need separate call server know download url)

response.downloadurl = app/media/fileid/document.pdf 

all need set,

window.location = item.downloadurl; 

this cause browser request resource server, response server must include content-disposition:attachment;. cause browser show download dialog.

p.s. have worked on similar functionality. if have questions please ask.

when want force browser show download prompt file (resource), must include content-disposition:attachment; in response (which did).


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -