我正在尝试使用 ionic/angular 将视频上传到 PHP 服务器 (laravel)。但是由于某种原因,请求总是在 API 上为空,但是如果我使用 Postman 发送它可以工作,我已经尝试多次更改 de 标头,但似乎没有任何效果
这是我提出请求的功能:
storeVideo(user_id, videoStrip, videoNoStrip, description, place_id, video_url_thumbnail,): Promise<any> {
const HttpUploadOptions = {
headers: new HttpHeaders({ "Content-Type": "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "enctype":"multipart/form-data"})
}
var blob = new Blob([videoStrip], { type: 'video/mp4' });
const formData = new FormData();
formData.append('videowithstrip', blob, 'teste');
return new Promise((resolve, reject) => {
this._http.post(`${environment.API_ENDPOINT}post/storeVideo`,
formData,HttpUploadOptions
).subscribe((posts: any) => resolve(posts), (err) => reject(err));
});
}
这是调用请求的函数
async save() {
//post-api
const loader = await this.loadingController.create({
message: 'Loading...'
});
await loader.present();
this._postService.storeVideo(
this.user.id,
this.videoStrip,
this.videoNoStrip,
this.description,
this.place_id,
this.videoThumb,
).then((post) => {
loader.dismiss();
if (post.id > 0) {
this.presentAlert('Sucess', '', () => {
this._router.navigateByUrl('/model/tabs/feed');
});
}
}).catch(async (error) => {
this.presentAlert('Ops', '', error);
});
}
我每次都对变量进行控制台记录,它们会显示我的数据,即使检查开发工具的标头请求和请求有效负载都很好。
知道如何解决这个问题吗?
谢谢