node.js 코드를 사용하여 A 저장소에서 이미지를 다운로드 한 다음 B 저장소에 업로드하는 기능을 만듭니다. 다른 작업을 계속하기 전에 모든 스트림을 강제로 완료하려고합니다. 나는이 방법을 시도했지만 성공하지 못했습니다. 예 : 실행하면 getImage이 실행됩니다. getImage이 완료되지 않으면 완료 될 때까지 A-> B-> C를 반복합니다. getImage을 완료합니다. 다른 작업을 계속하기 전에 모든 스트림을 강제로 완료하도록하려면 어떻게해야합니까? 나는 A -> B -> C를 실행하기 전에 getImage을 끝내기를 원한다.다른 작업을 계속하기 전에 모든 스트림을 강제로 종료하는 방법은 무엇입니까?
추 신 : pkgCloud를 사용하여 이미지를 IBM Object Storage에 업로드하고 있습니다.
function parseImage(imgUrl){
var loopCondition = true;
while(loopCondition){
getImages(imgUrl,imgName);
Do task A
Do task B
Do task C
}
}
function getImages(imgUrl, imgName) {
//Download image from A repository
const https = require('https');
var imgSrc;
var downloadStream = https.get(imgUrl, function (response) {
// Upload image to B repository.
var uploadStream = storageClient.upload({container: 'images', remote: imgName});
uploadStream.on('error', function (error) {
console.log(error);
});
uploadStream.on('success', function (file) {
console.log("upload Stream>>>>>>>>>>>>>>>>>Done");
console.log(file.toJSON());
imgSrc = "https://...";
});
response.pipe(uploadStream);
});
downloadStream.on('error', function (error) {
console.log(error);
});
downloadStream.on('finish', function() {
console.log("download Stream>>>>>>>>>>>>>>>>>Done");
});
return imgSrc;
}
어떤 함수가'imgSrc'를 정의합니까? 'uploadStream.on ('success''? – guest271314
) ([동기 및 비동기 프로그래밍 (node.js에서)의 차이점은 무엇입니까?] (http://stackoverflow.com/questions/16336367/what-is-the-difference- 사이 동기 및 비동기 프로그래밍 노드에서) – guest271314