Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: send blobs when running ipfs-http-client in the browser (#3184)
Browse files Browse the repository at this point in the history
To support streaming of native types with no buffering, normalise add input to blobs and upload using native FormData when the http client is run in the browser.

That is, if the user passes a blob to the http client in the browser leave it alone as enumerating blob contents cause the file data to be read.

Browser FormData objects do not allow you to specify headers for each multipart part which means we can't pass UnixFS metadata via the headers so we turn the metadata into a querystring and append it to the field name for each multipart part as a workaround.

Fixes #3138

BREAKING CHANGES:

- Removes the `mode`, `mtime` and `mtime-nsec` headers from multipart requests
- Passes `mode`, `mtime` and `mtime-nsec` as querystring parameters appended to the field name of multipart requests
  • Loading branch information
achingbrain authored Jul 23, 2020
1 parent 6a498e9 commit 6b24463
Show file tree
Hide file tree
Showing 18 changed files with 527 additions and 388 deletions.
24 changes: 18 additions & 6 deletions docs/core-api/FILES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ _Explore the Mutable File System through interactive coding challenges in our [P
- [The Regular API](#the-regular-api)
- [`ipfs.add(data, [options])`](#ipfsadddata-options)
- [Parameters](#parameters)
- [FileStream](#filestream)
- [FileObject](#fileobject)
- [FileContent](#filecontent)
- [Options](#options)
- [Returns](#returns)
- [`ipfs.addAll(source, [options])`](#ipfsaddallsource-options)
Expand Down Expand Up @@ -108,12 +111,19 @@ The regular, top-level API for add, cat, get and ls Files on IPFS

`data` may be:

* `Blob`
* `String`
* `Uint8Array`
* `FileContent` (see below for definition)
* `FileObject` (see below for definition)
* `Iterable<Uint8Array>`
* `AsyncIterable<Uint8Array>`
* `FileStream<FileContent>` (see below for definition)

##### FileStream

`FileStream` is a stream of `FileContent` or `FileObject` entries of the type:

```js
Iterable<FileContent|FileObject> | AsyncIterable<FileContent|FileObject> | ReadableStream<FileContent|FileObject>
```

##### FileObject

`FileObject` is a plain JS object of the following form:

Expand All @@ -136,10 +146,12 @@ If no `content` is passed, then the item is treated as an empty directory.

One of `path` or `content` _must_ be passed.

##### FileContent

`FileContent` is one of the following types:

```js
Uint8Array | Blob | String | Iterable<Uint8Array> | AsyncIterable<Uint8Array>
Uint8Array | Blob | String | Iterable<Uint8Array | Number> | AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>
```

`UnixTime` is one of the following types:
Expand Down
10 changes: 7 additions & 3 deletions packages/ipfs-core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@
},
"license": "MIT",
"dependencies": {
"blob-to-it": "0.0.1",
"browser-readablestream-to-it": "0.0.1",
"buffer": "^5.6.0",
"cids": "^0.8.3",
"err-code": "^2.0.0",
"ipfs-utils": "^2.2.2"
"ipfs-utils": "^2.2.2",
"it-all": "^1.0.1",
"it-map": "^1.0.0",
"it-peekable": "0.0.1"
},
"devDependencies": {
"aegir": "^23.0.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"delay": "^4.3.0",
"dirty-chai": "^2.0.1",
"it-all": "^1.0.1"
"dirty-chai": "^2.0.1"
}
}
298 changes: 0 additions & 298 deletions packages/ipfs-core-utils/src/files/normalise-input.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const normaliseContent = require('./normalise-content.browser')
const normaliseInput = require('./normalise-input')

/*
* Transforms any of the `ipfs.add` input types into
*
* ```
* AsyncIterable<{ path, mode, mtime, content: Blob }>
* ```
*
* See https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md#ipfsadddata-options
*
* @param input Object
* @return AsyncInterable<{ path, mode, mtime, content: Blob }>
*/
module.exports = (input) => normaliseInput(input, normaliseContent)
Loading

0 comments on commit 6b24463

Please sign in to comment.