如何使Firefox处理与firefox-addon-sdk POST请求的结果? [英] How to make Firefox handle the result of a POST request with firefox-addon-sdk?
问题描述
我想从我的插件发布图像到我的Servlet处理图像并返回一个PDF。该servlet工作。我只是不知道如何处理从我的插件得到的PDF。
$ p $ const $ request $ require(sdk / request )。请求;
...
let req = request({
url:http:// localhost:8090 / Whatever / PdfServlet,
content:params,
onComplete :function(response){
console.log(response.text)
}
});
req.post();
这里,object params 包含base64编码图像。一切正常,我可以看到控制台日志中的PDF流的开始。但是,如何让Firefox显示其打开/保存对话框,以便用户可以保存或查看PDF?
这是一个解决方案:
const querystring = require('sdk / querystring');
const winUtils = require('sdk / window / utils');
...
let stringStream = Cc [@ mozilla.org/io/string-input-stream; 1]。
createInstance(Ci.nsIStringInputStream);
stringStream.data = querystring.stringify(params);
让postData = Cc [@ mozilla.org/network/mime-input-stream; 1]。
createInstance(Ci.nsIMIMEInputStream);
postData.addHeader(Content-Type,application / x-www-form-urlencoded);
postData.addContentLength = true;
postData.setData(stringStream);
winUtils.getMostRecentBrowserWindow()。loadURI(http:// localhost:8090 / Whatever / PdfServlet,null,postData,null);
或者我可以打开一个新窗口,但是我不喜欢那个:
winUtils.openDialog({
args:[http:// localhost:8090 / Whatever / PdfServlet,null,null,postData ]
});
I'd like to post images from my addon to my Servlet that processes the images and returns a PDF. The servlet works. I just don't know how to handle the resulting PDF from my addon.
const request= require("sdk/request").Request;
...
let req= request({
url: "http://localhost:8090/Whatever/PdfServlet",
content: params,
onComplete: function (response) {
console.log(response.text)
}
});
req.post();
Here, object params contains the base64 encoded images. Everything works, I can see the beginning of the PDF stream in the console log. But how do I make Firefox show its open/save dialog so that the user can save or view the PDF?
Here's a solution:
const querystring= require('sdk/querystring');
const winUtils= require('sdk/window/utils');
...
let stringStream= Cc["@mozilla.org/io/string-input-stream;1"].
createInstance(Ci.nsIStringInputStream);
stringStream.data= querystring.stringify(params);
let postData= Cc["@mozilla.org/network/mime-input-stream;1"].
createInstance(Ci.nsIMIMEInputStream);
postData.addHeader("Content-Type", "application/x-www-form-urlencoded");
postData.addContentLength = true;
postData.setData(stringStream);
winUtils.getMostRecentBrowserWindow().loadURI("http://localhost:8090/Whatever/PdfServlet", null, postData, null);
Or I could open a new window, but I didn't like that:
winUtils.openDialog({
args: ["http://localhost:8090/Whatever/PdfServlet", null, null, postData]
});
这篇关于如何使Firefox处理与firefox-addon-sdk POST请求的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!