.zip 파일과 .xlsx 파일을 동시에 게시하는 엔드 포인트가 있습니다.Busboy와 Node가있는 ng-file-upload는 로컬에서는 작동하지만 서버에서는 작동하지 않습니다.
클라이언트 (각도 1) :
files.upload = Upload.upload({
url: '/api/files',
data: { xlsxFile: xlsxFile, zipFile: zipFile }
});
files.upload.then(
function (response) {
$scope.state = 'completed';
$scope.message = response.data.data;
},
function (error) {
$scope.state = 'error';
$scope.message = _.get(error, 'data.errors[0].meta.errorObj') || 'An unspecified error occurred, please check your files and try again.';
},
function (evt) {
progress = evt.loaded/evt.total;
}
);
서버 (노드) : 로컬로 실행 때 100 % 작동하지만, 그것은에서 실행중인 경우 :
const busboy = new Busboy({headers: req.headers});
var xlsxFileBuffers = [];
var zipFilePath = `${Math.random().toString(36).substring(5)}zipFile.zip`;
busboy.on('file', (fieldName, file, filename, encoding, mimeType) => {
if (!mimeType.includes('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') &&
!mimeType.includes('application/vnd.ms-excel') &&
!mimeType.includes('application/zip')
) return next('Invalid file type.');
if (fieldName === 'zipFile') {
file.pipe(fs.createWriteStream(zipFilePath));
}
else {
file.on('data', function(data) {
xlsxFileBuffers.push(data);
});
file.on('end', function() {
if (!xlsxFileBuffers.length) {
return next('Cannot read xlsx file.');
}
});
}
});
busboy.on('finish',() => {
console.log('busboy finish called');
if (xlsxFileBuffers.length > 0) {
console.log('we made it!');
}
});
req.pipe(busboy);
지금 여기에 흥미로운 부분이 온다 원격 서버이면 net::ERR_CONNECTION_RESET
으로 응답합니다. 오류 객체는 출력하지만, 연결이 닫힌 이유에 대해 알아 낸 유용한 정보가 아닌, 버스 보이 객체로 보이는 것을 인쇄합니다. 우리가 약간의 진전을 볼 수 있습니다 그래서 {upload: f, progress: 81, name: "test-xlsx.xlsx", lastModified: 1507565920197, lastModifiedDate: Mon Oct 09 2017 09:18:40 GMT-0700 (PDT)}
:
이 객체의 부분 비트입니다. 그리고 서버에는 .zip
파일이 있지만, 압축 해제 작업이 실패하기 때문에 완료되지 않았습니다.
추가 정보가 도움이되는지 알려주세요. 감사!
편집 : .zip 파일은 197KB이고 .xlsx 파일은 7KB입니다. 로컬에서 테스트 할 때 적어도 120MB 크기의 zip 파일로 작업했습니다.