Laravel /角度图片上传-重定向失败

时间:2019-04-03 11:01:54

标签: php angular ngx-bootstrap

我正在尝试通过laravel API和前端前端上传图像。

这是我的laravel函数

public function UploadAdvertImage(Property $property, PhotoRequest $request) 
{
    $image_name = $request->file('image_name')->getRealPath();;
    Cloudder::upload($image_name, null);

    $result = Cloudder::getResult();

    $photo = $property->photo()->create(['url' => $result['url'], 'public_id' => $result['public_id']]);

    return response()->json($photo);
}

我正在使用第三方api将图像存储在cloudinary中,然后在数据库中引用该图像。

上传照片是多零件形式的第二步。上传后,它尝试上传以进行广告/创建。说,这是整个表格的成角度的路线。

角度照片html

<input type="file" name="image_name" ng2FileSelect [uploader]="uploader" />

<button type="button" class="btn btn-success btn-s" 
  (click)="uploader.uploadAll()" 
  [disabled]="!uploader.getNotUploadedItems().length" >
      Upload an Image
</button>
<button mat-button matStepperNext>Next</button>

角度照片ts

export class AdvertPhotosComponent implements OnInit {
  @Input() photos: Photo[];
  baseUrl = environment.apiUrl;

  constructor(private advertService: AdvertService, private alertify: AlertifyService, public authService: AuthService,
    private formBuilder: FormBuilder) { }

currentProperty = JSON.parse(localStorage.getItem('property'));
url = this.baseUrl + 'advertisement/' + this.currentProperty.id + '/upload-image';
public uploader: FileUploader = new FileUploader({url: this.url, itemAlias: 'photo'});

ngOnInit() {
  this.uploader.onAfterAddingFile = (file) => { file.withCredentials = false; };
  this.uploader.onCompleteItem = (item: any, response: any, status: any, headers: any) => {
       console.log('ImageUpload:uploaded:', item, status, response);
       alert('File uploaded successfully');
   };
   }

  }

该图像根本没有上传,但是我收到一条消息说它已经上传了。我的“网络”标签中也显示以下内容。

Network Tab

Expanded Network Tab

0 个答案:

没有答案