Skip to content

Commit

Permalink
use the upload field to send the file, accepting a ReadStream
Browse files Browse the repository at this point in the history
A `ReadStream` is necessary here because of how SuperAgent's internals are implemented: `.attach` requires an explicit filename (which I don't want to do), and `.field` can infer the filename, but only from `ReadStream`s or other request objects.
  • Loading branch information
erikdesjardins committed Jul 18, 2016
1 parent 6ecc28b commit 9e00d18
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ deploy({
// the version to publish
version: '1.0.0',

// a Buffer or string containing a .zip (WebExtensions) or .xpi (Add-on SDK)
src: fs.readFileSync('path/to/zipped/extension.zip'),
// a ReadStream containing a .zip (WebExtensions) or .xpi (Add-on SDK)
src: fs.createReadStream('path/to/zipped/extension.zip'),
}).then(function() {
// success!
}, function(err) {
Expand Down
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ module.exports = function deploy(options) {
request
.put('https://addons.mozilla.org/api/v3/addons/' + extensionId + '/versions/' + extensionVersion + '/')
.set('Authorization', 'JWT ' + token)
.type('multipart/form-data')
.send(srcFile)
.field('upload', srcFile)
.end(function(err, response) {
if (err) {
var msg;
Expand Down
2 changes: 0 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ test.serial('full deploy', async t => {
t.is(publishReq.match[1], 'someId');
t.is(publishReq.match[2], 'someVersion');
t.regex(publishReq.headers['Authorization'], /^JWT /);
t.is(publishReq.headers['Content-Type'], 'multipart/form-data');
t.is(publishReq.params, 'someSrc');

// throws if invalid
jwt.verify(publishReq.headers['Authorization'].slice(4), 'someSecret', {
Expand Down

0 comments on commit 9e00d18

Please sign in to comment.