Hub JS Package

Hub JS Package

  • Users
  • Buckets
  • Threads
  • Textile Docs

›Buckets

Buckets

  • Buckets.copyAuth() method
  • Buckets.withUserAuth() method
  • Buckets.withKeyInfo() method
  • Buckets.getToken() method
  • Buckets.getTokenChallenge() method
  • Buckets.setToken() method
  • Buckets.withThread() method
  • Buckets.getOrCreate() method
  • Buckets.create() method
  • Buckets.existing() method
  • Buckets.root() method
  • Buckets.links() method
  • Buckets.list() method
  • Buckets.listPath() method
  • Buckets.listPathFlat() method
  • Buckets.listIpfsPath() method
  • Buckets.movePath() method
  • Buckets.open() method
  • Buckets.pushPath() method
  • Buckets.pushPaths() method
  • Buckets.pushPathAccessRoles() method
  • Buckets.pullPath() method
  • Buckets.pullPathAccessRoles() method
  • Buckets.pullIpfsPath() method
  • Buckets.remove() method
  • Buckets.removePath() method
  • Buckets.setPath() method

Experimental

  • Archive interface
  • ArchiveDealInfo interface
  • ArchiveStatus enum

Types

  • GetOrCreateOptions interface
  • GetOrCreateResponse interface
  • CreateOptions interface
  • CreateResponse interface
  • Links interface
  • Path interface
  • PathAccessRole enum
  • PathItem interface
  • Root interface
  • BuckMetadata interface

@textile/hub > Buckets > pushPath

Buckets.pushPath() method

Pushes a file to a bucket path.

Signature:

pushPath(key: string, path: string, input: any, options?: PushOptions): Promise<PushPathResult>;

Parameters

ParameterTypeDescription
keystringUnique (IPNS compatible) identifier key for a bucket.
pathstringA file/object (sub)-path within a bucket.
inputanyThe input file/stream/object.
optionsPushOptions

Returns:

Promise<PushPathResult>

Remarks

  • This will return the resolved path and the bucket's new root path. - If pushing NodeJS streams, ensure you set your highwatermark to an appropriate size (i.e., ~1024 bytes) for optimal behavior on slow or intermittent connections. See example below or use utils.createReadStream.

Example 1

Push a file to the root of a bucket

import { Buckets } from '@textile/hub'

const pushFile = async (buckets: Buckets, content: string, bucketKey: string) => {
   const file = { path: '/index.html', content: Buffer.from(content) }
   return await buckets.pushPath(bucketKey!, 'index.html', file)
}

Example 2

Push an folder in node.js

import fs from 'fs'
import util from 'util'
import glob from 'glob'
import { Buckets } from '@textile/hub'

const globDir = util.promisify(glob)

// expects an already setup buckets session using getOrCreate or withThread
const exists = async (buckets: Buckets, bucketKey: string, dir: string) => {
  const files = await globDir('<dir glob options>')
  return await Promise.all(files.map(async (file) => {
    const filePath = dir + '/' + file
    var content = fs.createReadStream(filePath, { highWaterMark: 1024 });
    const upload = {
      path: file,
      content
    }
    return await buckets.pushPath(bucketKey, file, upload)
  }))
}

← Buckets.open() methodBuckets.pushPaths() method →
  • Buckets.pushPath() method
  • Parameters
  • Remarks
  • Example 1
  • Example 2
Hub JS Package
Docs
Getting StartedThreadDBBuckets
Resources
All DocumentationProject SlackBlog
More
GitHubStar
Follow @textileio