[英]Angular 6 ng2-file-upload send list with file
我在Angular項目中有這段代碼,並使用ng2-file-upload上傳圖像。
export class Product {
id: string;
name: string;
imageUrl: string;
productCategoryId: string;
shopId: string;
productPropertyList: ProductProperty[] = [];
}
export class ProductProperty {
propertyId: number;
propertyName: string;
productId: string;
propertyValue: string;
}
當我嘗試通過文件發送數據時,服務器端的productPropertyList為空,而在發送之前它具有數據。
initializeFileUploader(categoryId, shopId) {
this.uploader = new FileUploader({
url: this.baseUrl + 'users/' + this.authService.decodedToken.nameid + '/products/CreateProduct',
additionalParameter: ['Url'],
authToken: 'Bearer ' + localStorage.getItem('token'),
isHTML5: true,
allowedFileType: ['image'],
autoUpload: false,
removeAfterUpload: true,
maxFileSize: 5 * 1024 * 1024
});
this.uploader.onAfterAddingFile = (file) => { file.withCredentials = false; };
this.uploader.onBuildItemForm = (item, form) => {
console.log(this.product.productPropertyList);
form.append('ProductCategoryId', categoryId);
form.append('ShopId', shopId);
form.append('Name', this.product.name);
form.append('PropertyList', this.product.productPropertyList);
};
}
如何發送陣列?
您可以對其進行JSON字符串化:
form.append('PropertyList',JSON.stringify(this.product.productPropertyList));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.