你如何在Keystone中使用Azure存储帐户?

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

How can I use Azure Storage Account with Keystone?

问题

我有一个需要迁移到Azure订阅的应用程序。技术栈包括NextJs、Prisma和Keystone。

它涉及一些文件上传操作,而Keystone内置支持S3存储。

是否有办法在S3的位置上使用Azure存储账户?

我尝试过使用https://www.npmjs.com/package/@k6-contrib/fields-azure,但无法使其工作。

英文:

I have an app that I need to move to an Azure subcription. the stack is NextJs, Prisma and Keystone.

It is doing some file uploading and Keystone have built in support for s3 storage.

Is there a way to use a Azure Storage account in place of an s3?

I tried using this https://www.npmjs.com/package/@k6-contrib/fields-azure but can't get it to work.

答案1

得分: 1

我得到了来自另一个来源的帮助,并成功解决了它。

我使用了这个包(https://www.npmjs.com/package/@k6-contrib/fields-azure),但不得不进行一些修改。

keystone.ts

添加导入

import {AzureStorageConfig, azureStorageImage} from "@k6-contrib/fields-azure";

然后需要为SA连接创建一个配置对象。

const azConfig: AzureStorageConfig = {
    azureStorageOptions: {
        account: process.env.AZURE_STORAGE_ACCOUNT_NAME || '',
        accessKey: process.env.AZURE_STORAGE_ACCESS_KEY || '',
        container: process.env.AZURE_STORAGE_CONTAINER || '',
        url: process.env.AZURE_STORAGE_ACCOUNT_HOST
            ? `${process.env.AZURE_STORAGE_ACCOUNT_HOST}${process.env.AZURE_STORAGE_CONTAINER}`
            : undefined,
    },
};

请注意,这与npm和示例中的说明略有不同。url 需要是 "host/container"。

然后需要设置与存储连接的字段。在我的情况下是 "logo" 字段。

logo: azureStorageImage({azureStorageConfig: azConfig})
  • AZURE_STORAGE_CONTAINER
    • 存储帐户中容器的名称。
  • AZURE_STORAGE_ACCOUNT_NAME
    • 存储帐户的名称。
  • AZURE_STORAGE_ACCESS_KEY
    • 存储帐户的访问密钥。
  • AZURE_STORAGE_ACCOUNT_HOST
    • 存储帐户的 URL/终端点。

希望这能帮助有类似问题的其他人。

英文:

I got help from another source and managed to solve it.

I used the package (https://www.npmjs.com/package/@k6-contrib/fields-azure) but had to make some modifications.

In keystone.ts

Add import

import {AzureStorageConfig, azureStorageImage} from "@k6-contrib/fields-azure";

Then a config object needs to be created for the SA-connection.

const azConfig: AzureStorageConfig = {
    azureStorageOptions: {
        account: process.env.AZURE_STORAGE_ACCOUNT_NAME || '',
        accessKey: process.env.AZURE_STORAGE_ACCESS_KEY || '',
        container: process.env.AZURE_STORAGE_CONTAINER || '',
        url: process.env.AZURE_STORAGE_ACCOUNT_HOST
            ? `${process.env.AZURE_STORAGE_ACCOUNT_HOST}${process.env.AZURE_STORAGE_CONTAINER}`
            : undefined,
    },
};

Note that this differs somewhat from the instructions at npm and in the example. The url needed to be "host/container".

Then the fields connected to the storage needed to be set. In my case the "logo" field.

logo: azureStorageImage({azureStorageConfig: azConfig})
  • AZURE_STORAGE_CONTAINER
    • The name of the container in the storage account.
  • AZURE_STORAGE_ACCOUNT_NAME
    • The name of the storage account.
  • AZURE_STORAGE_ACCESS_KEY
    • The access key for the storage account.
  • AZURE_STORAGE_ACCOUNT_HOST
    • The url/endpoint to the storage account.

Hope this can help someone out there with a similar problem.

huangapple
  • 本文由 发表于 2023年7月13日 14:30:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676497.html
匿名

发表评论

匿名网友

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

确定