从 Angular 上传文件到 Nginx Openresty lua 上传

问题描述

我使用 openresty 和 lua 创建了一个文件上传系统。它在从 Nginx 提供静态 html 页面并通过在发布到的 Nginx.conf 文件的路径中调用 content_by_luafile 上传文件时起作用。我试图让它在一个单独运行的(跨源)角度应用程序上工作,但我要么得到一个

"no cross-origin-resource-allowed header on requested resource" 

在浏览器控制台中,或者我得到一个

 "no boundary defined in content type" 

Nginx error.log 文件中。

我已经尝试从 content-type: 'multipart/form-data' 以及 undefined 格式化传出标题

我已将 CORS 标头添加到我的 Nginx“位置”(请参阅​​:https://enable-cors.org/server_nginx.html

角度上传功能如下所示:

 upload(file: File): Observable<HttpEvent<any>> {
    const formData: FormData = new FormData();

    formData.append('testFileName',file);
    let headers = new HttpHeaders({
      'Content-Type': 'multipart/form-data'});
  let options = { headers: headers };

    const req = new HttpRequest('POST',`${this.baseUrl}/upfile`,formData,options);

    return this.http.request(req);
  }

openresty上传系统: https://programmersought.com/article/81471844718/

我知道如果我构建 --prod 并以这种方式运行它可能会起作用,因为它不再是跨域的,但我喜欢拥有单独的 Nginx 服务器或路径的想法,仅用于可以连接的上传使用跨源 Angular 应用。

OpenResty 似乎是构建多用途互操作中间件的绝佳工具。

关于如何实现这一目标的任何想法?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)