将base64图像上传到supabase

发布于 2025-01-30 18:31:58 字数 114 浏览 6 评论 0原文

我的网站希望减少用户可以使用图像所做的事情...因此,为了增加安全性,我们希望将图像源保留为Base64字符串,而不是Supabase存储URL。这是否可以通过Supabase存储,我是否必须将字符串保存在DB中?

My website wants to reduce the amount of things users can do with the images...so for added security, we want to keep the image sources as a base64 strings instead of a supabase storage URL. Is this possible through supabase storage, do will I have to save the string in the db?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

讽刺将军 2025-02-06 18:31:58
import { decode } from 'base64-arraybuffer'

const image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA='

const base64 = image.split('base64,')[1]

const { data, error } = await supabase
   .storage
   .from('avatars')
   .upload('public/avatar1.png', decode(base64), {
       contentType: 'image/png'
   })
import { decode } from 'base64-arraybuffer'

const image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA='

const base64 = image.split('base64,')[1]

const { data, error } = await supabase
   .storage
   .from('avatars')
   .upload('public/avatar1.png', decode(base64), {
       contentType: 'image/png'
   })
回心转意 2025-02-06 18:31:58

如果要将图像保存为base64,则需要将其保存为表中的记录。

使用存储,您可以创建一个复杂的策略并从存储中下载文件,并且不会直接共享链接。

If you want to save your image as base64 you need to save it as a record in your table.

With storage you can create a complex policy and download files from storage and don't share links directly.

拥有 2025-02-06 18:31:58

尝试一下

    const base64 = base64image.split('base64,')[1]
    const buffer = Buffer.from(base64, 'base64');
    const { data, error } = await supabase.storage
      .from('avatars')
      .upload('avatar.png', buffer, {
        contentType: 'image/png', // Adjust based on your image type
      });

try this

    const base64 = base64image.split('base64,')[1]
    const buffer = Buffer.from(base64, 'base64');
    const { data, error } = await supabase.storage
      .from('avatars')
      .upload('avatar.png', buffer, {
        contentType: 'image/png', // Adjust based on your image type
      });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文