Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

绑定cloudflare r2 图床异常 #545

Closed
wangdaodaodao opened this issue Feb 28, 2025 · 6 comments
Closed

绑定cloudflare r2 图床异常 #545

wangdaodaodao opened this issue Feb 28, 2025 · 6 comments

Comments

@wangdaodaodao
Copy link

按照要求,填入各种 api 后,提示

错误

readableStream.getReader is not a function. (In'readableStream.getReader)',
'readableStream.getReader' is undefined)
请问什么原因。

@canopysgit
Copy link

我也是配置完cloudfareR2后报错了。

另外想问一下,默认提供的那个图床是长期能用的么?我就是怕以后不能用了导致图片都加载失效,如果能长期用,自己不折腾也OK

@wangdaodaodao
Copy link
Author

wangdaodaodao commented Feb 28, 2025

我也是配置完cloudfareR2后报错了。

另外想问一下,默认提供的那个图床是长期能用的么?我就是怕以后不能用了导致图片都加载失效,如果能长期用,自己不折腾也OK

默认的我也不用,
第一,资料容易泄露,其次,有效期不能保证。
还是 cloudflare 的安全点,都是自己的。

@LurnD
Copy link

LurnD commented Mar 5, 2025

Image 请问R2是在自定义里配置吗

@myysophia
Copy link

cloudfareR2 确实有问题

@yanglbme
Copy link
Member

yanglbme commented Mar 5, 2025

谢谢反馈,已修复 @LurnD @myysophia @canopysgit

@lurenyang418
Copy link
Contributor

谢谢反馈,已修复 @LurnD @myysophia @canopysgit

抱歉看到的晚了,似乎是 aws 的 sdk 出了点问题 aws/aws-sdk-js-v3#6834 .我之前适配的时候版本是 3.716.0. 我看仓库中已经升级到最新了. 下面讨论中 aws/aws-sdk-js-v3#6834 (comment) 暂时给了一个解决方案, 可能会慢一点

async function r2Upload(file: File) {
  const { accountId, accessKey, secretKey, bucket, path, domain } = JSON.parse(
    localStorage.getItem(`r2Config`)!,
  )
  const dir = path ? `${path}/` : ``
  const filename = dir + getDateFilename(file.name)
  const client = new S3Client({ region: `auto`, endpoint: `https://${accountId}.r2.cloudflarestorage.com`, credentials: { accessKeyId: accessKey, secretAccessKey: secretKey } })
  // new 
  const body = await file.arrayBuffer()

  return new Promise<string>((resolve, reject) => {
    const putObjectCommand = new PutObjectCommand({
      Bucket: bucket,
      Key: filename,
      ContentType: file.type,
      // Body: file,
      Body: new Uint8Array(body),
    })
    client.send(putObjectCommand).then(() => {
      resolve(`${domain}/${filename}`)
    }).catch((err) => {
      reject(err)
    })
  })
}

PS: 修复用的预签名的方法,这也是一种实现。(我想少装一个库,就用了直接的方法)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants