1.0.7 • Published 3 years ago

strapi-provider-upload-local-custom-path v1.0.7

Weekly downloads
35
License
SEE LICENSE IN LI...
Repository
github
Last release
3 years ago

strapi-provider-upload-local-custom-path

Configurations

This provider has two parameters: path and sizeLimit.

Example

./config/plugins.js

module.exports = ({ env }) => ({
  upload: {
    provider: 'local-custom-path',
    providerOptions: {
      path: env('UPLOADS_PATH') || '.tmp/media',
      sizeLimit: 100000
    },
  },
});

The sizeLimit parameter must be a number. Be aware that the unit is in bytes, and the default is 1000000. When setting this value high, you should make sure to also configure the body parser middleware maxFileSize so the file can be sent and processed. Read more here

Note

You will likely need to add ./middlewares/upload/index.js

'use strict';

const { resolve } = require('path');
const range = require('koa-range');
const koaStatic = require('koa-static');
const get = require('lodash/get')

module.exports = strapi => ({
  initialize() {
    const configPublicPath = strapi.config.get(
      'middleware.settings.public.path',
      strapi.config.paths.static
    );

    const staticDir = get(strapi, "config.plugins.upload.providerOptions.path", resolve(strapi.dir, configPublicPath));

    strapi.app.on('error', err => {
      if (err.code === 'EPIPE') {
        return;
      }

      strapi.app.onerror(err);
    });

    strapi.router.get('/uploads/(.*)', range, koaStatic(staticDir, { defer: true }));
  },
});

Resources

Links

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago