Skip to content

Commit 9e6dfe7

Browse files
MichaelMureAlan Shaw
authored and
Alan Shaw
committed
fix: invalid multipart/form-data (ipfs#948)
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.
1 parent 8f378a3 commit 9e6dfe7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/utils/send-files-stream.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const once = require('once')
77
const prepareFile = require('./prepare-file')
88
const Multipart = require('./multipart')
99

10-
function headers (file) {
11-
const name = file.path
10+
function headers (file, i) {
11+
const filename = file.path
1212
? encodeURIComponent(file.path)
1313
: ''
1414

15-
const header = { 'Content-Disposition': `file; filename="${name}"` }
15+
const header = { 'Content-Disposition': `form-data; name="data${i}"; filename="${filename}"` }
1616

1717
if (!file.content) {
1818
header['Content-Type'] = 'application/x-directory'
@@ -43,7 +43,7 @@ module.exports = (send, path) => {
4343
const next = once(_next)
4444
try {
4545
const files = prepareFile(file, options)
46-
.map((file) => Object.assign({ headers: headers(file) }, file))
46+
.map((file, i) => Object.assign({ headers: headers(file, i) }, file))
4747

4848
writing = true
4949
eachSeries(

0 commit comments

Comments
 (0)