Я пытаюсь отправить изображение и некоторые данные JSON в одном запросе http post.Заголовок
this.httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
}
, а моя HTML-часть -
<input #imageInput type="file" name="add-logo" accept="image/*"
id="add-logo" (change)="onFileChanged(imageInput)" class="form-control cust-field" placeholder="">
, а функция component.ts -
logo:File
onFileChanged(imageInput: any) {
const file: File = imageInput.files[0];
this.logo = file;
}
И ошибка
HttpErrorResponse {headers: HttpHeaders, status: 422, statusText: "Unprocessable Entity", url: "myUrl", ok: false, …}
error:
messages: ["The logo field is required."]
status: false
__proto__: Object
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
message: "Http failure response for url: 422 Unprocessable Entity"
name: "HttpErrorResponse"
ok: false
status: 422
statusText: "Unprocessable Entity"
url: "url"
Я отправляю этот объект в API
{first_name: "Firts Name", last_name: "Last Name", email: "a@gmail.com", phone: "+923045203200", password: "03045203200", …}
accounting_method: "Cash"
business_location: [{…}]
business_location_name: "myLegalBusiness"
business_name: "myLegalBusiness"
business_phone: "0304520320055"
business_system_name: "tradeName"
confirm_p: "03045203200"
currency: "ALL"
currency_id: 1
ein_ssn: "EIN34"
email: "asad@gmail.com"
first_name: "Firts Name"
fy_end_month: "MARCH"
last_name: "Last Name"
logo: File {name: "users.png", lastModified: 1561615773639, lastModifiedDate: Thu Jun 27 2019 11:09:33 GMT+0500 (Pakistan Standard Time), webkitRelativePath: "", size: 2550, …}
number_of_stores: 1
password: "03045203200"
phone: "+923045203200"
store_name: "store"
store_type: "Franchise"
unique_code: "145dd" }