Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 将图像存储在带有角度传感器的Laravel上_Angular_Laravel - Fatal编程技术网

Angular 将图像存储在带有角度传感器的Laravel上

Angular 将图像存储在带有角度传感器的Laravel上,angular,laravel,Angular,Laravel,我试图在我的db上存储一个图像,以laravel api作为后端,并以angular作为前端传递它,就像我尝试它发送文件一样,但当laravel处理“图像”时,它被存储为空,我的意思是白色或完全黑色 在我的角度组件中,当输入类型文件更改时,我启动一个事件 fileEvent(e){ const reader = new FileReader(); if(e.target.files && e.target.files.length) { co

我试图在我的db上存储一个图像,以laravel api作为后端,并以angular作为前端传递它,就像我尝试它发送文件一样,但当laravel处理“图像”时,它被存储为空,我的意思是白色或完全黑色

在我的角度组件中,当输入类型文件更改时,我启动一个事件

fileEvent(e){
    const reader = new FileReader();
    
    if(e.target.files && e.target.files.length) {
      const [file] = e.target.files;
      reader.readAsDataURL(file);  
      reader.onload = () => { 
        this.imageSrc = reader.result as string;
        this.companyForm.patchValue({
          logo: reader.result
        });
      };
    }
  }
我的反应式表单有以下字段

companyForm = this._formBuilder.group({
    id: [1],
    tradename: ['', Validators.required],
    rfc: ['', Validators.required],
    sat_name: ['', Validators.required],
    phone: ['', Validators.required],
    email: ['', Validators.required],
    zip_code: ['', Validators.required],
    calle: ['', Validators.required],
    numero_exterior: ['', Validators.required],
    numero_interior: [''],
    asentamiento: ['', Validators.required],
    municipio: ['', Validators.required],
    estado: ['', Validators.required],
    ciudad: ['', Validators.required],
    pais: ['', Validators.required],
    logo: ['', Validators.required]
  });
我发送到API的方式

create(token, company): Observable<any>{
    let json = JSON.stringify(company);
    let params = "json=" + json;

    let headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded').set('Authorization', token);

    return this._http.post(this.url + 'empresa', params, {headers:headers});
}
这就是它存储图像的方式

您可以通过特定文件夹上传图像,并将字符串本地路径存储到数据库,而图像存储基本上不会通过db just path存储图像。

当然,我知道,实际上在我的数据库中,我只是将路由和图像存储在特定文件夹中,但是,当图像存储在文件夹中时,我会尝试查看它,并没有显示什么,只是一个透明的图像或一个不完整的图像
$folderPath = "uploads/company/";
$image_parts = explode(";base64,", $params->logo);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = base64_decode($image_parts[1]);
$file = $folderPath . uniqid() . '.png';
file_put_contents($file, $image_base64);
$company->logo = $file;