I am using the Add-on builder and I need to receive binary data (image). I would like to do this using the request module but as you can see from the documentation:
https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/addon-kit/docs/request.html
There are only text and json properties and raw is absent.
How should I receive binary data in the add-on script?
You cannot do this using the
requestmodule, you will have to use the regularXMLHttpRequestvia chrome authority. Something like this should work:The mechanism to ensure that the request is aborted if your extension is suddenly disabled is rather awkward, that’s the main reason the
requestmodule exists rather than simply giving youXMLHttpRequest. Note that it is important to callonUnload.unload()once the request finishes, otherwise the Add-on SDK will keep it in the list of methods to be called on unload (a memory leak). See documentation ofunloadmodule.