@textile/hub > Buckets > pushPaths
Buckets.pushPaths() method
Pushes an iterable of files to a bucket.
Signature:
pushPaths(key: string, input: any, options?: PushOptions): AsyncIterableIterator<PushPathsResult>;
Parameters
Parameter | Type | Description |
---|---|---|
key | string | Unique (IPNS compatible) identifier key for a bucket. |
input | any | The input array of file/stream/objects. |
options | PushOptions | PushOptions to control response stream. |
Returns:
AsyncIterableIterator<PushPathsResult>
Example
Push all files in a directory to the root of a bucket
import fs from 'fs'
import path from 'path'
import util from 'util'
import glob from 'glob'
import { Buckets } from '@textile/hub'
const globDir = util.promisify(glob)
const pushMultipleFiles = async (buckets: Buckets, bucketKey: string, directory: string, globPattern: string) => {
const options = {
directory,
nodir: true,
}
const files = await globDir(globPattern, options)
if (files.length === 0) {
throw Error(`No files found: ${directory}`)
}
let streams = []
for (const file of files) {
const stream = fs.createReadStream(
path.join(directory, file), {
highWaterMark: 1024,
}
)
streams.push({
path: file,
content: stream,
})
}
return await buckets.pushPaths(bucketKey, streams)
}