From d1af3a77ae814e36ee6aaf10d8d081e190c98b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Thu, 21 Feb 2019 15:15:26 +0100 Subject: [PATCH] fix: invalid multipart/form-data According to https://tools.ietf.org/html/rfc7578#section-4.2, in a Content-Disposition header of a part in a multipart/form-data body: - the disposition must be of type `form-data` - a `name` parameter (not explicitely specified by the RFC, but I suppose non-empty) As this `name` parameter is unused by IPFS, this commit simply generate a placeholder with a counter, to conform to the HTTP specification. --- src/utils/send-files-stream.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/send-files-stream.js b/src/utils/send-files-stream.js index aff2cdcc9..2005a359c 100644 --- a/src/utils/send-files-stream.js +++ b/src/utils/send-files-stream.js @@ -7,12 +7,12 @@ const once = require('once') const prepareFile = require('./prepare-file') const Multipart = require('./multipart') -function headers (file) { - const name = file.path +function headers (file, i) { + const filename = file.path ? encodeURIComponent(file.path) : '' - const header = { 'Content-Disposition': `file; filename="${name}"` } + const header = { 'Content-Disposition': `form-data; name="data${i}"; filename="${filename}"` } if (!file.content) { header['Content-Type'] = 'application/x-directory' @@ -43,7 +43,7 @@ module.exports = (send, path) => { const next = once(_next) try { const files = prepareFile(file, options) - .map((file) => Object.assign({ headers: headers(file) }, file)) + .map((file, i) => Object.assign({ headers: headers(file, i) }, file)) writing = true eachSeries(