1
서버 측에서 처리하도록 선택된 데이터 행 ('/ salarypayments/generateGirofile')을 보내려면 다음과 같은 기능을 가지고 있으며 파일을 다운로드하려면 클라이언트 측에 다시 URL을 반환합니다.여러 파일 다운로드
genGiro: function(model) {
var self = this;
var controller = this.get('controller');
var chosenPayslips = [];
controller.get('chosenPayslips').forEach(function(chosenPayslip) {
chosenPayslips.push(chosenPayslip.get('id'));
});
this.get('authObject').authorize('authorizer:application', (headerName, headerValue) => {
const requestHeaders = {};
requestHeaders[headerName] = headerValue;
Ember.$.ajax({
type: "POST",
headers: requestHeaders,
data:{
payslipsArray: chosenPayslips,
amountPaid: controller.get('amountPaid'),
service_type: controller.get('service_type'),
process_mode: controller.get('process_mode'),
valueDate: moment(controller.get('valueDate')).format('YYYYMMDD'),
countTran: 6,
user: this.get('authObject.session.content.authenticated.user.id')
},
url: this.store.adapterFor('application').get('namespace') + '/salarypayments/generateGirofile',
success: function(response){
var link = document.createElement("a");
link.style.display = 'none';
document.body.appendChild(link);
response.forEach(function(download){
link.href = download.link;
link.download = download.filename;
link.click();
});
document.body.removeChild(link);
$('#myModal').modal('hide');
location.reload();
},
error: function(xhr, status, error){
console.log('Error ' + error);
}
});
});
}
그러나 1 파일 다운로드 만 시작할 수 있으며 2 개의 파일이 있다고 가정합니다. 배열 응답에는 다음과 같은 속성이 있습니다.
{ link: 'http://127.0.0.1/folder/1/file1.txt', filename: 'file1.txt'}
{ link: 'http://127.0.0.1/folder/1/file2.txt', filename: 'file2.txt'}
파일을 압축하는 이외의 방법은 무엇입니까? 사용자를위한 추가 단계를 생성하지 않는 것이 좋습니다. – chris
여러 파일에 대해 여러 앵커를 만들고 모든 앵커를 반복하여 클릭 할 수 있습니까? Theoractically이 작동해야합니다 –
이 작업을 수행하는 방법에 대한 예제를 줄 수 있습니까? – chris