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 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)