我正在尝试更新一个具有文件上传功能的实体。我可以使用add方法发送(添加)FormData,但无法更新。 NgRx给出以下错误:
错误:主键不能为空/未定义。
这甚至可能吗?还是我做错了什么。请看下面的代码:
const ad = {
id: form.id,
accountId: this.accountId
}
const data = new FormData();
data.append('ad', JSON.stringify(ad));
// photos is an array of uploaded files
if(this.photos.length) {
this.photos.forEach(photo => {
data.append('offure_ad', photo, photo['name']);
});
}
// NgRx Data update mothod
this.adService.update(data);
请引导我正确的方向。谢谢
请尝试以下代码
const ad = {
id: form.id,
accountId: this.accountId
}
const data = new FormData();
data.append('ad', JSON.stringify(ad));
// photos is an array of uploaded files
if(this.photos.length) {
this.photos.forEach(photo => {
data.append('offure_ad', photo, photo['name']);
});
}
// send ad like below
this.adService.update(data,ad);