Sails.JS图片上传无法在生产环境中使用? 在开发阶段工作

问题描述 投票:0回答:1

我将Vue.JS用于前端,将Sails.JS用于后端。

除了图像上传,其他所有操作都在我的本地机器和生产环境中进行。

我得到这些错误:

POST http://{mysailsdomain}/api/v1/upload 413 (Request Entity Too Large)

Failed To Load http://{mysailsdomain}/api/v1/upload: No 'Access-Control-Origin' header is present on the requested resource. Origin 'http://{myvuedomain}' is therfore not allowed access. The response had HTTP status code 413.

Uncaught (in promise) B {url: "http://{mysailsdomain}/api/v1/upload", ok: false, status: 0, statusText: "", headers: U, …}

Cross-Origin Read Blocking (CORB) blocked cross-origin response http://{mysailsdomain}/api/v1/upload with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.

我的config/security.js

cors: {
    allRoutes: true,
    allowOrigins: '*',
    allowCredentials: false,
  },

我用错误搜索了一下,有人建议将此代码添加到我的config/http.js

bodyParser: (function () {
      var opts = {limit:'50mb'};
      var fn;

      // Default to built-in bodyParser:
      fn = require('skipper');
      return fn(opts);

    })

我添加了代码,但是问题仍然存在。

这是我的production.js

onlyAllowOrigins: [
   'http://{myvuejsdashboard}',
   'http://{myvuejsapp}'
 ]

我什至试图注释掉所有onlyAllowOrigins但仍然没有运气。

我正在使用Sails v1.0.2。

ubuntu nginx vue.js sails.js digital-ocean
1个回答
0
投票

您的生产环境设置是什么? 它位于代理服务器ngnix的后面,因为代理服务器上设置了限制,因此您的代理服务器似乎拒绝了上载。

如果使用的是ngnix,则可以在ngnix配置中将client_max_body_size设置为50MB,然后重新启动ngnix以重新加载配置。

这应该可以解决您的第一个问题。 [ 413请求实体太大) ]

© www.soinside.com 2019 - 2024. All rights reserved.