Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid local uploads path #6925

Merged
merged 6 commits into from Jul 27, 2020
Merged

Fix invalid local uploads path #6925

merged 6 commits into from Jul 27, 2020

Conversation

akcyp
Copy link
Contributor

@akcyp akcyp commented Jul 7, 2020

File upload provider does not consider the strapi configuration. This patch should fix the problem.

Description of what you did:

// app.js
const path = require('path');
const strapiDir = path.join(__dirname, './backend');

const Strapi = require(path.join(strapiDir, `/node_modules/strapi`));
const strapi = Strapi({
  dir: strapiDir
});
strapi.start();

This configuration generates the following error when uploading the image:

ENOENT: no such file or directory, open 'C:\Users\XYZ\Desktop\backend\public\uploads\screenshot_862571e640.jpeg'

The correct directory should be:

C:\Users\XYZ\Desktop\app\backend\public\uploads\screenshot_862571e640.jpeg

akcyp added 2 commits July 7, 2020 13:54
File upload provider does not consider the strapi configuration. This patch should fix the problem.
@derrickmehaffy
Copy link
Member

This will need to be checked against Mac and Linux

@@ -23,6 +23,10 @@ module.exports = {
});
}
};
const getStaticPath = () => path.join(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't need to be a function. you can use

const uploadDir = path.join(strapi.dir, strapi.config.middleware.settings.public.path || strapi.config.paths.static)

@alexandrebodin alexandrebodin added this to the 3.1.1 milestone Jul 22, 2020
@alexandrebodin alexandrebodin added source: core:upload Source is core/upload package issue: bug Issue reporting a bug labels Jul 22, 2020
Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thank you 💯

Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't push to the fork you made for some reason...

You will need to fix the tests in packages/strapi-plugin-upload/test/tests/bootstrap.test.js

set the globa.strapi like so:

global.strapi = {
      dir: process.cwd(),
      admin: {
        services: { permission: { actionProvider: { register } } },
      },
      log: {
        error() {},
      },
      config: {
        get() {
          return 'public';
        },
        paths: {},
        info: {
          dependencies: {},
        },
      },
      plugins: {
        upload: {
          config: {
            provider: 'local',
          },
        },
      },
      store() {
        return {
          get() {
            return null;
          },
          set: setStore,
        };
      },
    };

Please also use strapi.config.get('middleware.settings.public.path', strapi.config.paths.static) to get the path :)

@akcyp
Copy link
Contributor Author

akcyp commented Jul 22, 2020

You mean packages/strapi-plugin-upload/test/__tests__/bootstrap.test.js ? 😄
I made changes but when running jest ./packages/strapi-plugin-upload/test/__tests__/bootstrap.test.js tests failed 😢
The error ReferenceError: register is not defined occurs at line

services: { permission: { actionProvider: { register } } },

@codecov
Copy link

codecov bot commented Jul 22, 2020

Codecov Report

Merging #6925 into master will decrease coverage by 7.89%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6925      +/-   ##
==========================================
- Coverage   26.17%   18.28%   -7.90%     
==========================================
  Files        1130     1021     -109     
  Lines       15406    11895    -3511     
  Branches     2436     1704     -732     
==========================================
- Hits         4033     2175    -1858     
+ Misses       9557     8266    -1291     
+ Partials     1816     1454     -362     
Flag Coverage Δ
#front 18.28% <ø> (+<0.01%) ⬆️
#unit ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...permissions/admin/src/components/EditForm/index.js 0.00% <0.00%> (ø)
...ainers/EditViewDataManagerProvider/utils/schema.js 0.00% <0.00%> (ø)
...t-type-builder/controllers/validation/constants.js
packages/strapi-utils/lib/sanitize-entity.js
packages/strapi-admin/domain/user.js
packages/strapi-admin/domain/condition.js
...strapi/lib/services/entity-validator/validators.js
packages/strapi-admin/services/auth.js
...manager/services/utils/configuration/attributes.js
...ackages/strapi/lib/load/check-reserved-filename.js
... and 100 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3363415...a16202c. Read the comment docs.

@alexandrebodin
Copy link
Member

@akcyp You need to update your branch (merge master) and then follow the previous comment ;)

@alexandrebodin alexandrebodin removed this from the 3.1.1 milestone Jul 23, 2020
@akcyp
Copy link
Contributor Author

akcyp commented Jul 26, 2020

Thanks and forgive me for making corrections now, but I was on vacation. I hope everything will be ok now! 💯 😄

@alexandrebodin alexandrebodin added this to the 3.1.2 milestone Jul 27, 2020
Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

@alexandrebodin alexandrebodin merged commit 8c40d21 into strapi:master Jul 27, 2020
juandl pushed a commit to juandl/strapi that referenced this pull request Jul 27, 2020
* Fix invalid local uploads path

File upload provider does not consider the strapi configuration. This patch should fix the problem.

* getStaticPath -> uploadDir

* Use config.get method

* plugin-upload tests fix

Signed-off-by: Juan David <juand.business@gmail.com>
Tomaszal pushed a commit to Tomaszal/strapi that referenced this pull request Jul 28, 2020
* Fix invalid local uploads path

File upload provider does not consider the strapi configuration. This patch should fix the problem.

* getStaticPath -> uploadDir

* Use config.get method

* plugin-upload tests fix

Signed-off-by: Tomaszal <mrtomaszal@gmail.com>
@moritz-halke
Copy link

Hi, with 3.0.* we had configured paths.static to use a absolute path (e.g. /mnt/storage/uploads) instead of the default ./uploads location. With this change the strapi.dir always prepends the pwd() location, thus screwing with our config.

As a workaround, cloned the local provider (making a custom provider) and removed the strapi.dir prefix. But I'm not sure if this is the best approach.

Is there a better way to configure an absolute path for the upload folder?

@alexandrebodin
Copy link
Member

@moritz-halke a fix is ready for the next release: #7280

gilfernandes pushed a commit to onepointconsulting/strapi that referenced this pull request Aug 13, 2020
* Fix invalid local uploads path

File upload provider does not consider the strapi configuration. This patch should fix the problem.

* getStaticPath -> uploadDir

* Use config.get method

* plugin-upload tests fix

Signed-off-by: Gil Fernandes <gil.fernandes@onepointltd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug source: core:upload Source is core/upload package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants