duanbi7247 2017-12-27 15:53
浏览 81

如何将带有Angular的FormData传递给Laravel操作方法

I have an existing site built using Laravel. I am "duplicating" the action methods to use Angular, when I duplicated the action that posts a file I didn't get it to work. The $_FILES and $_POST global variables are not being set.

Template: I have an input of type file, when a file is selected I want to send it to the server.

<form enctype="multipart/form-data" [formGroup]="frmUploadFotoUm" (change)="onChange($event)">
    <input type="file"  [formControl]="frmUploadFotoUm.controls['fuUm']"  />
    <progress min="0" value="{{progressStatus}}" max="100"></progress>
  </form>

Handler:

onChange(event) : void
  {            
      let fileList: FileList = event.target.files;   
      let file: File = fileList[0];   
      let formData: FormData = new FormData();

      formData.append('imagem', file);
      formData.append('imgNum', 1);
      formData.append('imgNome', "testandoAngular");
      formData.append('tipoAnuncio', "venda");
      formData.append('tipoImovel', "casa");
      formData.append('imovelId', 361);
      formData.append('dirAnuncio', 8);

      this.http.post('http://www.example.com/apiuploadfotos/store', formData, {headers: new Headers({ 'Content-Type' : undefined})}
      ).subscribe(res => {});


  }

The Laravel action method:

Here I get "not working" all the time.

  public function store(Request $request)
{
    if($_FILES)
    {
        echo "working";
        exit();
    }
    else
    {
        echo "not working";
        exit();
    }
 }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧