我的上传资产的预览未在Strapi仪表板中显示。

huangapple go评论71阅读模式
英文:

Preview of my uploaded assets to Private Azure blob storage is not showing in strapi dashboard

问题

上传到私人 Azure Blob 存储后,我的上传资产的预览不显示在 Strapi 仪表板中。我正在使用我的存储访问密钥来为 Strapi 提供权限。我能够通过 Strapi 仪表板上传和删除文件,但无法预览和下载。任何快速帮助将不胜感激。已经为此挣扎了几天。

以下是我在 Strapi 代码的 middleware.js 中使用的代码:

    name: "strapi::security",
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          "connect-src": ["'self'", "https:"],
          "img-src": [
            "'self'",
            "data:",
            "blob:",
            "dl.airtable.com",
            "https://market-assets.strapi.io",
            "https://*.blob.core.windows.net",
            "https://*.blob.core.windows.net/my_bucket_name",
          ],
          "media-src": [
            "'self'",
            "data:",
            "blob:",
            "dl.airtable.com",
            "https://*.blob.core.windows.net",
            "https://*.blob.core.windows.net/my_bucket_name",
          ],
          upgradeInsecureRequests: null,
        },
      },
    },
  },```


以下是我在配置中为 Azure 给予 Strapi 权限的部分:

```upload: {
      config: {
        provider: 'strapi-provider-upload-azure-storage',
        providerOptions: {
          account: env('STORAGE_ACCOUNT'),
          accountKey: env('STORAGE_ACCOUNT_KEY'),
          serviceBaseURL: env('STORAGE_URL'),
          containerName: env('STORAGE_CONTAINER_NAME'),
          defaultPath: 'assets',
          maxConcurrent: 100,
          expiresIn:3600,
        }
      }
    },```


[以下是您可以找到图像的链接][1]


  [1]: https://i.stack.imgur.com/xhZrN.png

<details>
<summary>英文:</summary>

[enter image description here][1]The preview of my uploaded assets is not showing in Strapi dashboard after uploading the file to my Private Azure blob storage. I am using my storage access key to provide permission to Strapi. I am able to upload and delete the file through the Strapi dashboard but the preview and download are not available. Any quick help will be much appreciated. Struggling with this for a couple of days.

Below is the code I am using in middleware.js of Strapi code

```{
    name: &quot;strapi::security&quot;,
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          &quot;connect-src&quot;: [&quot;&#39;self&#39;&quot;, &quot;https:&quot;],
          &quot;img-src&quot;: [
            &quot;&#39;self&#39;&quot;,
            &quot;data:&quot;,
            &quot;blob:&quot;,
            &quot;dl.airtable.com&quot;,
            &quot;https://market-assets.strapi.io&quot;,
            &quot;https://*.blob.core.windows.net&quot;,
            &quot;https://*.blob.core.windows.net/my_bucket_name&quot;,
          ],
          &quot;media-src&quot;: [
            &quot;&#39;self&#39;&quot;,
            &quot;data:&quot;,
            &quot;blob:&quot;,
            &quot;dl.airtable.com&quot;,
            &quot;https://*.blob.core.windows.net&quot;,
            &quot;https://*.blob.core.windows.net/my_bucket_name&quot;,
          ],
          upgradeInsecureRequests: null,
        },
      },
    },
  },```


Below is the configuration where I am giving permission access to Strapi for Azure

```upload: {
      config: {
        provider: &#39;strapi-provider-upload-azure-storage&#39;,
        providerOptions: {
          account: env(&#39;STORAGE_ACCOUNT&#39;),
          accountKey: env(&#39;STORAGE_ACCOUNT_KEY&#39;),
          serviceBaseURL: env(&#39;STORAGE_URL&#39;),
          containerName: env(&#39;STORAGE_CONTAINER_NAME&#39;),
          defaultPath: &#39;assets&#39;,
          maxConcurrent: 100,
          expiresIn:3600,
        }
      }
    },```
[Below is the link where you can find the image][1]


  [1]: https://i.stack.imgur.com/xhZrN.png

</details>


# 答案1
**得分**: 0

```javascript
account: env("STORAGE_ACCOUNT"),
accountKey: env("STORAGE_ACCOUNT_KEY"),
serviceBaseURL: env("STORAGE_URL"), // optional
containerName: env("STORAGE_CONTAINER_NAME"),
defaultPath: "assets",
cdnBaseURL: env("STORAGE_CDN_URL")

"media-src": [
    "'self'",
    "data:",
    "blob:",
    "dl.airtable.com",
    /**
    * 注意:如果使用STORAGE_URL,请用process.env.STORAGE_URL替换`https://${process.env.STORAGE_ACCOUNT}.blob.core.windows.net`
    * 如果使用CDN URL,请确保在CSP头部包含该URL process.env.STORAGE_CDN_URL
    */
    `https://${process.env.STORAGE_ACCOUNT}.blob.core.windows.net`,
],
upgradeInsecureRequests: null,

  • 确保在应用程序的相应路径中创建文件夹。
英文:

>Followed this MSDoc for Srapi.

Code:

account: env(&quot;STORAGE_ACCOUNT&quot;),
        accountKey: env(&quot;STORAGE_ACCOUNT_KEY&quot;),
        serviceBaseURL: env(&quot;STORAGE_URL&quot;), // optional
        containerName: env(&quot;STORAGE_CONTAINER_NAME&quot;),
        defaultPath: &quot;assets&quot;,
        cdnBaseURL: env(&quot;STORAGE_CDN_URL&quot;)

  &quot;media-src&quot;: [
            &quot;&#39;self&#39;&quot;,
            &quot;data:&quot;,
            &quot;blob:&quot;,
            &quot;dl.airtable.com&quot;,
            /**
 * Note: If using a STORAGE_URL replace `https://${process.env.STORAGE_ACCOUNT}.blob.core.windows.net` w/ process.env.STORAGE_URL
 * If using a CDN URL make sure to include that url in the CSP headers process.env.STORAGE_CDN_URL
 */
            `https://${process.env.STORAGE_ACCOUNT}.blob.core.windows.net`,

          ],
          upgradeInsecureRequests: null,

  • Make sure to please the folder in the respective path of the app.

Output :

我的上传资产的预览未在Strapi仪表板中显示。

huangapple
  • 本文由 发表于 2023年6月8日 14:37:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76429202.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定