nft.storage icon indicating copy to clipboard operation
nft.storage copied to clipboard

Why can't we stream upload to cloudflare workers?

Open Gozala opened this issue 4 years ago • 4 comments

Gozala avatar Jun 14 '21 16:06 Gozala

@Gozala You might find this useful - this is working for me fine using node, just using superagent to stream a file into IPFS. I think the 100mb limit is there for the workers still (your other issue) but for simply avoiding OOM on the node end it works.

import { NFTStorage, Blob } from 'nft.storage'
import request from 'superagent'
import { URL } from 'url'
import { pipeline, PipelineSource } from 'stream'

const client = new NFTStorage({ token: config.IPFS_STORAGE_KEY })

const storeStream = async (stream: PipelineSource<any>): Promise<string> => {
  const { endpoint, token } = client
  const url = new URL('/upload', endpoint).toString()

  return new Promise((resolve, reject) => {
    const req = request.post(url).set(NFTStorage.auth(token))
    let res: Record<any, any>
    req.once('response', (rez) => res = rez.body)
    pipeline(stream, req, (err: Error) => {
      if (err) return reject(err)
      if (!res?.value?.cid) {
        return reject(new Error(`Invalid response: ${JSON.stringify(res)}`))
      }
      return resolve(res.value.cid)
    })
  })
}

yocontra avatar Jun 15 '21 17:06 yocontra

@Gozala can we close this?

dchoi27 avatar Jan 10 '22 14:01 dchoi27

@dchoi27 I think this is your call, but this was a meta issue to try and work out if there is the way we could overcome CF 100mb limit. @hugomrdias had multiple calls with them and if I recall correctly they seemed to think we should not have this issue & where going to look into that. I'm not sure what is the status there.

On the other hand if we end up with sessions IDs and rootless CAR uploads we would probably not care about this any more.

Gozala avatar Jan 26 '22 19:01 Gozala

I've been stuck here for a long time. I want to know what's the reason and how to solve it. I've tried it many times and it still looks like this. Does anyone know how to solve it? My nodejs18.10 and nftup1.02. image

LinmyChi-you avatar Oct 10 '23 23:10 LinmyChi-you

We're closing this issue. If you still need help please open a new issue.

elizabeth-griffiths avatar Apr 17 '24 22:04 elizabeth-griffiths