ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

์ด๋ฏธ์ง€ URL๋งŒ์„ ๊ฐ€์ง€๊ณ  fs๋ชจ๋“ˆ์„ ํ†ตํ•ด ์ด๋ฏธ์ง€ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œํ•˜๋Š” ์ฝ”๋“œ ํ˜•์‹์ž…๋‹ˆ๋‹ค.


1
2
3
4
5
6
7
8
9
10
11
12
var fs = require('fs');
var exec = require('child_process').exec;
var request = require('request');
 
function downloadFunction(path,url,filename,res,callback) {
    request.head(url,function(err,res,body){
        console.log('content-type:',res.headers['content-type']);
        console.log('content-length:',res.headers['content-length']);
    request(url).pipe(fs.createWriteStream(path+filename)).on('close',callback);
    });    
}
exports.downloadFunction = downloadFunction;
cs


์ด์™€๊ฐ™์ด ์‚ฌ์šฉ์ž ๋ชจ๋“ˆํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜์—ฌ ํ˜ธ์ถœํ•˜๋Š” ๊ณณ์—์„œ ์ด๋ฏธ์ง€๋ฅผ ๋ฐ”๋กœ ๋‹ค์šด๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.


์—ฌ๊ธฐ์„œ ๋งํ•˜๋Š” ์ด๋ฏธ์ง€ URL์€ ๋‹ค์šด๋กœ๋“œ๊ฐ€ ๊ฐ€๋Šฅํ•œ ๋งํฌํ˜•ํƒœ์—ฌ์•ผํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ๋ฐฉ๋ฒ•์ด ์žˆ๊ฒ ์ง€๋งŒ ์ €๋Š” ํ”Œ๋ฆฌ์ปค API๋ฅผ ์ด์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var Flickr = require('flickr-sdk');
var flickr = new Flickr('ํ”Œ๋ฆฌ์ปค API Key๊ฐ’');
var download = require('./download');
var fs = require('fs');
var response = require('response');
 
function galleryFunction() {
    var path = './gallery_img/';
    flickr.galleries.getPhotos({
        gallery_id: '๊ฐค๋Ÿฌ๋ฆฌ์•„์ด๋”” ๊ฐ’'
    }).then(function(res){
        res.body.photos.photo.forEach(function(element){
            var url ='https://farm'+element.farm+'.staticflickr.com/'+element.server+'/'+element.id+'_'+element.secret+'.jpg'
            download.downloadFunction(path,url,element.id,response,function(){ console.log('done')});
        });
    })
}
exports.galleryFunction = galleryFunction;
cs


์ผ๋‹จ ์‚ฌ์šฉ์ž๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ๋” require ์œผ๋กœ ์„ ์–ธ์„ ํ•ด์ฃผ๊ณ  ๋‹ค์šด๋กœ๋“œ๊ฐ€ ๊ฐ€๋Šฅํ•œ ์ด๋ฏธ์ง€ URL ๋งํฌ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.


URLํ˜•์‹์€ ์œ„์™€๊ฐ™์ด ๊ฐ๊ฐ ์‚ฌ์ง„์ด ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์†์„ฑ ๊ฐ’๊ณผ ํ”Œ๋ฆฌ์ปค์—์„œ ์ œ๊ณตํ•˜๋Š” ์ด๋ฏธ์ง€ ๋งํฌ ํ˜•์‹์„ ๋”ฐ๋ผ์„œ ์จ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.


ํ”Œ๋ฆฌ์ปค ๊ฐค๋Ÿฌ๋ฆฌ์— ์กด์žฌํ•˜๋Š” ๋ชจ๋“  ์‚ฌ์ง„์„ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์„ ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— forEach๋ฌธ์„ ํ†ตํ•ด์„œ ๊ฐ๊ฐ ์‚ฌ์ง„์— ๋Œ€ํ•œ URL์„ ๋งŒ๋“ค์–ด์„œ 


downloadFunction์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋„ฃ์–ด์ฃผ๋ฉด ๋.

๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
๊ธ€ ๋ณด๊ด€ํ•จ