How can I send multiple files to Service (JAVA)? #1055
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When I transfer multiple files, I want to call up the POST function and send the file data to Service (JAVA).
What should I do?
component.ts
const URL = 'http://localhost:8080/programFile/';
constructor (private cms: CommonService, private service: ProgramFileRegisterService){
this.uploader = new FileUploader({
url: URL,
disableMultipart: true, // 'DisableMultipart' must be 'true' for formatDataFunction to be called.
formatDataFunctionIsAsync: false,
formatDataFunction: async (item) => {
return new Promise(
(resolve,reject) => {resolve({
name: item._file.name,
length: item._file.size,
contentType: item._file.type,
date: new Date()
});
});
}
});
service.ts
public post(path: string, data: any): Observable {
console.log('API포스트' + path);
let body = JSON.stringify(data);
console.log('token : ' + sessionStorage.getItem('token'));
this.setHeader("x-auth-token", sessionStorage.getItem('token'));
return this.http.post(
${this.API_URL}${path}, body, {headers: this.headers}).map(this.extractData)
.catch(this.handleError);
}