Strapi blod storage

最近给strapi配置了 blod storage:

yarn add strapi-provider-upload-azure-storage

.env添加:

STORAGE_ACCOUNT=XXX
STORAGE_ACCOUNT_KEY=XXX
STORAGE_CONTAINER_NAME=XXX

plugins.ts

module.exports = function({ env }) {
  return {
    upload: {
      config: {
        provider: "strapi-provider-upload-azure-storage",
        providerOptions: {
          account: env("STORAGE_ACCOUNT"),
          accountKey: env("STORAGE_ACCOUNT_KEY"),
          containerName: env("STORAGE_CONTAINER_NAME"),
          defaultPath: "assets",
        },
      },
    },
  };
};

然后在strapi admin page访问文件或者图片,会出现:

Access to video at
‘https://XXXX/assets/Canada_20_Nova_20_Scotia_20rusted_20chain_20links_20zoom_20in_preview_b40e3f062c.mp4’
from origin ‘http://localhost:1337’ has been blocked by CORS policy:
No ‘Access-Control-Allow-Origin’ header is present on the requested
resource.

可以修改config/middlewares.ts里面的’strapi::security’ , 如果你是用aws或者ali的storage, 后面改对应的域名应该也是一样的。

{
    name: 'strapi::security',
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          'connect-src': ["'self'", 'https:',"http"],
          'img-src': ["'self'", 'data:', 'blob:', 'https://'+env('STORAGE_ACCOUNT')+'.blob.core.windows.net'],
          'media-src': ["'self'", 'data:', 'blob:', 'https://'+env('STORAGE_ACCOUNT')+'.blob.core.windows.net'],
          upgradeInsecureRequests: null,
        },
      },
    },
  },

在这里插入图片描述

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值