How can I send multiple files to Service (JAVA)? #1055

Open
opened 2018-09-26 14:17:29 +00:00 by LEEJUKIM · 0 comments
LEEJUKIM commented 2018-09-26 14:17:29 +00:00 (Migrated from github.com)

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);
}

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<any> { 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); }
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#1055