I am using angular and typescript to send my file in a post request body to backend which is in golang, where it parses the file and uploads the data in file in the DB. When I am sending the file from Postman, the file is read and the data is being inserted in the DB successfully, which means my backend code is working just fine. When I am sending it from Typescript, it is giving me EOF error. Please find the code below -
Angular -
<input (change)="getFile($event.target.value,$event)" type="file" id="fileUpload" name="fileUpload" class="form-control"
accept=".csv" />
TypeScript -
file: File
getFile(event_value, event){
this.file = event.target.files[0];
fileUpload(this.file)
}
fileUpload(file: any){
let url = `abc/abc/abc`
let header = {'Content-Type':'multipart/form-data; boundary=----abc', 'Authorization': 'authorizationToken'}
return this.http.post(url, {"file": file}, {headers: header})
.map((response: Response) => response.json())
.catch(this.handleError)
}
Error in Go:
{"data":{"error":"multipart: NextPart: EOF","code":102,"data":null,"url":""},"level":"error","msg":"{multipart: NextPart: EOF 102 \u003cnil\u003e }","time":"2019-02-12T11:33:00-05:00"}
Am I missing something, that needs to be sent in the header?
Thank you in advance!