Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: invalid multipart/form-data (#948)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MichaelMure authored and Alan Shaw committed Jul 11, 2019
1 parent 8f378a3 commit 9e6dfe7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils/send-files-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9e6dfe7

Please sign in to comment.