User Cannot Add/upload To File Collections

by ADMIN 43 views

Introduction

In this article, we will delve into the issue of users being unable to add or upload files to file collections in NocoBase. This problem has been reported in the NocoBase GitHub repository, and we will provide a detailed analysis of the issue, including the steps to reproduce it, the expected behavior, and the relevant logs.

Describe the Bug

The bug occurs when a user with a member role attempts to upload a file to a file collection via the UI or REST API. The error message received is:

{
    "errors": [
        {
            "message": "Invalid URL",
            "code": "ERR_INVALID_URL"
        }
    ]
}

Environment

The issue has been reported in the following environment:

  • NocoBase version: 1.7 beta 23
  • Database type and version: Mysql/PostgreSQL
  • OS: Ubuntu/MacOS
  • Deployment Methods: Git/Docker
  • Docker image version: nocobase:beta
  • NodeJS version: 20+

How to Reproduce

To reproduce the issue, follow these steps:

  1. Deploy NocoBase
  2. Create a file collection, for example, my_media
  3. Allow signup on basic auth
  4. Edit permission to member role
    • Uncheck all General action permissions
    • Choose Action permissions
    • Select my_media then Config Individual
      • Add new: allow
      • View: All records
      • Edit: Own records
      • Delete: Own records
  5. Edit UI, add my_media to menu, add data table to that collection. Enable Upload
  6. Allow member to see Desktop routes as my_media menu
  7. Logout and signup new account
  8. Login to new account
  9. Go to my_media and upload new file

Expected Behavior

The expected behavior is that the user should be able to upload a file to the file collection without any errors.

Screenshots

Unfortunately, there are no screenshots available for this issue.

Logs

The relevant logs for this issue are:

TypeError: Invalid URL
    at new URL (node:internal/url:806:29)
    at encodeURL (/app/nocobase/node_modules/@nocobase/plugin-file-manager/dist/server/utils.js:79:21)
    at PluginFileManagerServer.getFileURL (/app/nocobase/node_modules/@nocobase/plugin-file-manager/dist/server/server.js:280:42)
    at _AsyncEmitter.<anonymous> (/app/nocobase/node_modules/@nocobase/plugin-file-manager/dist/server/server.js:268:36)
    at run (/app/nocobase/node_modules/@nocobase/utils/lib/mixin/AsyncEmitter.js:49:19)
    at _AsyncEmitter.emitAsync (/app/nocobase/node_modules/@nocobase/utils/lib/mixin/AsyncEmitter.js:63:13)
    at dev_media3.<anonymous> (/app/nocobase/node_modules/@nocobase/database/lib/model-hook.js:90:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    async dev_media3.runHooks (/app/nocobase/node_modules/sequelize/lib/hooks.js:96:7)
    at async dev_media3.findAll (/app/nocobase/node_modules/sequelize/lib/model.js:1142:7)
    at async dev_media3.findOne (/app/nocobase/node_modules/sequelize/lib/model.js:1240:12)
    at async model.reload (/app/nocobase/node_modules/sequelize/lib/model.js:2562:22)
    at async app.resourcer.use.before (/app/nocobase/node_modules/@nocobase/plugin-file-manager/dist/server/actions/index.js:63:22)
    at async handleFieldSourceMiddleware (/app/nocobase/node_modules/@nocobase/plugin-data-source-main/dist/server/server.js:443:7)
    at async mergeReverseFieldWhenSaveCollectionField (/app/nocobase/node_modules/@nocobase/plugin-data-source-main/dist/server/server.js:417:7)
    at async templateDataMiddleware (/app/nocobase/node_modules/@nocobase/plugin-block-template/dist/server/middlewares/templateData.js:45:3) {
  code: 'ERR_INVALID_URL',
  input: 'null'
}

Conclusion

In conclusion, the issue of users being unable to add or upload files to file collections in NocoBase is a complex problem that requires a detailed analysis of the environment, steps to reproduce, expected behavior, and relevant logs. By following the steps outlined in this article, developers can reproduce the issue and provide valuable feedback to the NocoBase team to help resolve this problem.

Recommendations

Based on the analysis, the following recommendations are made:

  • The NocoBase team should investigate the issue further to determine the root cause of the problem.
  • The team should provide a fix for the issue, which may involve updating the plugin-file-manager or plugin-data-source-main packages.
  • The team should provide clear instructions on how to reproduce the issue and the expected behavior.
  • The team should provide relevant logs and error messages to help developers diagnose the issue.

Related Issues

This issue is related to the following GitHub issues:

Introduction

In our previous article, we delved into the issue of users being unable to add or upload files to file collections in NocoBase. In this article, we will provide a Q&A section to help answer some of the most frequently asked questions related to this issue.

Q: What is the root cause of the issue?

A: The root cause of the issue is a complex problem that requires a detailed analysis of the environment, steps to reproduce, expected behavior, and relevant logs. However, based on the analysis, it appears that the issue is related to a bug in the plugin-file-manager or plugin-data-source-main packages.

Q: How can I reproduce the issue?

A: To reproduce the issue, follow these steps:

  1. Deploy NocoBase
  2. Create a file collection, for example, my_media
  3. Allow signup on basic auth
  4. Edit permission to member role
    • Uncheck all General action permissions
    • Choose Action permissions
    • Select my_media then Config Individual
      • Add new: allow
      • View: All records
      • Edit: Own records
      • Delete: Own records
  5. Edit UI, add my_media to menu, add data table to that collection. Enable Upload
  6. Allow member to see Desktop routes as my_media menu
  7. Logout and signup new account
  8. Login to new account
  9. Go to my_media and upload new file

Q: What is the expected behavior?

A: The expected behavior is that the user should be able to upload a file to the file collection without any errors.

Q: What are the relevant logs for this issue?

A: The relevant logs for this issue are:

TypeError: Invalid URL
    at new URL (node:internal/url:806:29)
    at encodeURL (/app/nocobase/node_modules/@nocobase/plugin-file-manager/dist/server/utils.js:79:21)
    at PluginFileManagerServer.getFileURL (/app/nocobase/node_modules/@nocobase/plugin-file-manager/dist/server/server.js:280:42)
    at _AsyncEmitter.<anonymous> (/app/nocobase/node_modules/@nocobase/plugin-file-manager/dist/server/server.js:268:36)
    at run (/app/nocobase/node_modules/@nocobase/utils/lib/mixin/AsyncEmitter.js:49:19)
    at _AsyncEmitter.emitAsync (/app/nocobase/node_modules/@nocobase/utils/lib/mixin/AsyncEmitter.js:63:13)
    at dev_media3.<anonymous> (/app/nocobase/node_modules/@nocobase/database/lib/model-hook.js:90:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async dev_media3.runHooks (/app/nocobase/node_modules/sequelize/lib/hooks.js:96:7)
    at async dev_media3.findAll (/app/nocobase/node_modules/sequelize/lib/model.js:1142:7)
    at async dev_media3.findOne (/app/nocobase/node_modules/sequelize/lib/model.js:124012)
    at async model.reload (/app/nocobase/node_modules/sequelize/lib/model.js:2562:22)
    at async app.resourcer.use.before (/app/nocobase/node_modules/@nocobase/plugin-file-manager/dist/server/actions/index.js:63:22)
    at async handleFieldSourceMiddleware (/app/nocobase/node_modules/@nocobase/plugin-data-source-main/dist/server/server.js:443:7)
    at async mergeReverseFieldWhenSaveCollectionField (/app/nocobase/node_modules/@nocobase/plugin-data-source-main/dist/server/server.js:417:7)
    at async templateDataMiddleware (/app/nocobase/node_modules/@nocobase/plugin-block-template/dist/server/middlewares/templateData.js:45:3) {
  code: 'ERR_INVALID_URL',
  input: 'null'
}

Q: How can I provide feedback to the NocoBase team?

A: To provide feedback to the NocoBase team, you can:

  • Create a new issue on the NocoBase GitHub repository
  • Provide a detailed description of the issue, including the steps to reproduce and the expected behavior
  • Attach relevant logs and error messages
  • Engage with the NocoBase community on the NocoBase Forum

Q: What is the current status of the issue?

A: The current status of the issue is that it is being investigated by the NocoBase team. The team is working to determine the root cause of the problem and provide a fix.

Q: When can I expect a fix for the issue?

A: The NocoBase team is working to provide a fix for the issue as soon as possible. However, the exact timeline for the fix is not yet available.

Conclusion

In conclusion, the Q&A section provides valuable information and insights into the issue of users being unable to add or upload files to file collections in NocoBase. By following the steps outlined in this article, developers can reproduce the issue and provide valuable feedback to the NocoBase team to help resolve this problem.