Plugin enabling image uploading to azure storage from strapi.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
- strapi@4.0.0+
Inside your strapi project run the following
yarn add strapi-provider-upload-azure-storage
# or
npm install strapi-provider-upload-azure-storage
To enable the provider, create or edit the file at ./config/plugins.js
.
This is an example plugins.js
file for Azure storage:
module.exports = ({ env }) => ({
upload: {
config: {
provider: "strapi-provider-upload-azure-storage",
providerOptions: {
account: env("STORAGE_ACCOUNT"),
accountKey: env("STORAGE_ACCOUNT_KEY"),//either account key or sas token is enough to make authentication
sasToken: env("STORAGE_ACCOUNT_SAS_TOKEN"),
serviceBaseURL: env("STORAGE_URL"), // optional
containerName: env("STORAGE_CONTAINER_NAME"),
defaultPath: "assets",
cdnBaseURL: env("STORAGE_CDN_URL"), // optional
},
},
},
});
Property | Required | Description |
---|---|---|
account | true | Azure account name |
accountKey | true | Secret access key |
sasToken | false | SAS Token, either accountKey or SASToken is required |
serviceBaseURL | false | Base service URL to be used, optional. Defaults to https://${account}.blob.core.windows.net |
containerName | true | Container name |
defaultPath | true | The path to use when there is none being specified. Defaults to assets |
cdnBaseURL | false | CDN base url |
Due to the default settings in the Strapi Security Middleware you will need to modify the contentSecurityPolicy settings to properly see thumbnail previews in the Media Library. You should replace strapi::security string with the object bellow instead as explained in the middleware configuration documentation.
To allow the azure storage content to be displayed, edit the file at ./config/middlewares.js
.
You should replace the strapi::security
string with the object below instead, see the Middlewares configuration documentation for more details.
./config/middlewares.js
module.exports = [
// ...
{
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",
/**
* 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`,
],
"media-src": [
"'self'",
"data:",
"blob:",
"dl.airtable.com",
/**
* 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,
},
},
},
},
// ...
];
serviceBaseURL
is optional, it is useful when connecting to Azure Storage API compatible services, like the official emulator Azurite. serviceBaseURL
would then look like http://localhost:10000/your-storage-account-key
.
When serviceBaseURL
is not provided, default https://${account}.blob.core.windows.net
will be used.
cdnBaseURL
is optional, it is useful when using CDN in front of your storage account. Images will be returned with the CDN URL instead of the storage account URL.
Contributions are welcome
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Jake Feldman - Initial work - jakeFeldman
This project is licensed under the MIT License - see the LICENSE.md file for details
- strapi.io
- Azure