1.0.0 • Published 4 years ago
strapi-provider-upload-firebase-resize v1.0.0
strapi-provider-upload-firebase-resize
Configurations
Your configuration is passed down to the provider.
Example
./extensions/upload/config/settings.json
{
"provider": "firebase-resize",
"providerOptions": {
"bucket": "your bucket name",
"serviceAccount": {
"type": "service_account",
"project_id": "your id",
"private_key_id": "your private key",
"private_key": "-----BEGIN PRIVATE KEY----- your key \n-----END PRIVATE KEY-----\n",
"client_email": "your client.gserviceaccount.com",
"client_id": "your id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot"
},
"optimize": {
"resize": true,
"width": 1000,
"height": 1000
},
"settings": {
"awsUploadFolder": "your upload folder"
},
"params": {
"Bucket": "strapi-app"
}
}
}
Where to get firebaseConfig JSON and bucket name
Service Accout
Go to your Firebase account
Project settings → Service account → Click "Generate new private key".
The JSON should look like this :
{
"type": "service_account",
"project_id": "your id",
"private_key_id": "your private key",
"private_key": "-----BEGIN PRIVATE KEY----- your key \n-----END PRIVATE KEY-----\n",
"client_email": "your client.gserviceaccount.com",
"client_id": "your id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot"
}
Bucket name
Go to your Firebase account → Storage
You should see your bucket name on the "Files" tab, next to the link symbol (🔗) at the top of the page. Example : gs://my-bucketname.appspot.com
Run this in your controller to delete resources from firebase when related records are removed
/api/articles/controllers/articles.js
'use strict';
const { parseMultipartData, sanitizeEntity } = require('strapi-utils');
module.exports = {
async delete(ctx) {
const { id } = ctx.params;
const entity = await strapi.services.restaurants.delete({ id });
if (entity) {
if (entity.featurette.length > 0) {
entity.featurette.forEach(image => {
strapi.plugins.upload.services.upload.remove(image);
strapi.plugins.upload.provider.delete(image);
});
}
}
return sanitizeEntity(entity, { model: strapi.models.restaurants });
}
};
"# strapi-provider-upload-aws-s3-sharp-resize" "# strapi-provider-upload-firebase-resize"