Extension Auto-Installer, Wget replacement

Discussion related to extensions like Extension Auto-Installer or Google Search link fix.
Locked
Andy

Extension Auto-Installer, Wget replacement

Post by Andy »

Hi,

I would like to send a file to Extension Auto-Installer, but not from wget, but from my nodejs script. As you may know, there are a tone of modules for nodejs that replicate the POST behavior. See for instance,
https://github.com/mikeal/request
https://github.com/timoxley/file-uploader

Unfortunately I couldn't make them work, here is a sample nodejs application,

Code: Select all

var request   = require('request');
var path      = require('path');
var fs        = require('fs');

var filepath = path.join(__dirname, 'myextension.xpi'); //path to xpi file

fs.createReadStream(filepath, {encoding: null}).pipe(request.post('http://localhost:8888'))
I am getting this error,

Code: Select all

Warning: WARN addons.xpi: Download failed: [Exception... "Component returned failure code: 0x8052000b (NS_ERROR_FILE_CORRUPTED) [nsIZipReader.open]"  nsresult: "0x8052000b (NS_ERROR_FILE_CORRUPTED)"  location: "JS frame :: resource://gre/modules/XPIProvider.jsm :: AI_loadManifest :: line 4555"  data: no]
Source file: resource://gre/modules/XPIProvider.jsm
Line: 4555
Any idea how to solve this? I think it is very useful to eliminate wget usage, especially for windows users.
Wladimir Palant

Re: Extension Auto-Installer, Wget replacement

Post by Wladimir Palant »

The file has to be the entire request body, it shouldn't be encoded via multipart or such. From what I can tell, node.js allows doing it like this:

Code: Select all

var req = require("http").request({
  hostname: 'localhost',
  port: 8888,
  path: '/',
  method: 'POST'
}, function(res) {});
req.write(fileData);
req.end();
You need to read the file data first by usual means.
Locked