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 对象存储显示图片的时候 400 bad request,文字和上传图片是可以的 #2436

Closed
edonyzpc opened this issue Oct 24, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@edonyzpc
Copy link

Describe the bug

如下图所示,配置好 R2 存储之后,添加图片,然后查看记录发现获取图片失败。

  • CORS 已经配置
[
  {
    "AllowedOrigins": [
      "*"
    ],
    "AllowedMethods": [
      "GET",
      "HEAD"
    ],
    "AllowedHeaders": [
      "*"
    ],
    "MaxAgeSeconds": 3600
  }
]
image

Steps to reproduce

  1. 按照指导文档配置 R2 存储
  2. 添加图片
  3. 查看记录的时候图片

Screenshots or additional context

No response

@edonyzpc edonyzpc added the bug Something isn't working label Oct 24, 2023
@Issues-translate-bot
Copy link

Issue is not in English. It has been translated automatically.


Title: Cloudflare R2 object storage gets 400 bad request when displaying images, text and uploaded images are OK

@athurg
Copy link
Contributor

athurg commented Oct 25, 2023

Maybe there's something wrong with your Cloudflare configurations, I suggest you to check that first.

@edonyzpc
Copy link
Author

edonyzpc commented Oct 25, 2023

@athurg Thank you for your reply, I tried the Cloudflare R2 configurations but it failed. So CORS can not be blamed.

I tried to access the object file in Chrome, and there is some response like the following image.
image

It seems that R2 S3 API is not supporting this way to access, the src attribute of img is ${R2_Bucket_S3_API}/${bucket_name}/image_object.png, if I configure the public access with custom domains provided by Cloudflare it worked.
image

So I checked the memos R2 storage configuration, and I found that I missed the URL prefix configuration when checking the screenshot of document. However, according to Cloudflare, it is not a good idea for product use. And it still not working, I don't know what does it mean of URL prefix and URL suffix in R2 configuration.
image

Can memos support customized domain public access configuration for R2?
image

And I tested it successfully by adding customized javascript to auto-replace the image URL. Of course, it's testing, the code can be more elegant when it is in the backend.

function refresher() {
    setTimeout(function () {
        for (item of document.getElementsByClassName('mt-2')) {
            for (img of item.getElementsByTagName('img')) {
                if (img.src.startsWith('https://img.edony.ink/memos')) continue;
                img.setAttribute('src', 'https://img.edony.ink/memos/' + img.src.split('/')[img.src.split('/').length - 1]);
            }
        }
    }, 1500)
}

setInterval(function () {
    refresher();
}, 30000)

@edonyzpc
Copy link
Author

it seems that it is R2 access problem not memos and close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants