boundary = "H#pB$Ky6Vs+Q8ioY_buA"
data = ""
for (i = 0; i < files.length; i++) {data += "--" + boundary + "\r\nContent-Disposition:form-data;name=file" + (i + 1) + ";filename=.png" + "\r\n\n" + fs.readFileSync(files[i]).toString("binary") + "\r\n"}
data += "--" + boundary + "--"
request = http.request(
{
method: "POST",
path: URL.path,
host: URL.host,
headers: {"Content-Type": "multipart/form-data;boundary=" + boundary}
},
function (response) {
var data = ""
response.on("data", function (chunk) {data += chunk})
response.on("end", function () {/* здесь можно распарсить ответ сервера и получить ссылки на изображения без использования метода «photos.save» */})
}
)
request.write(data, "binary")
request.end()
var path = require('path');
var request = require('request');
var http = require('http');
var fs = require('fs');
var uploadDir = 'C:\/Node\/';
var urlPrefix = 'http://e-shuushuu.net/images/';
var regExpImageURLWrapper = new RegExp('(?:<img src="\/images\/thumbs\/)(.*?)"', 'gim');
var pageAmount = 2;
function getCurrentImage(imageUrl)
{
var fileName = path.join(uploadDir, imageUrl);
var newRequest = request(urlPrefix + imageUrl);
newRequest.pause();
newRequest.on('response', function(resp)
{
if((resp.statusCode === 200) && (resp.headers['content-type'].match('image')))
{
newRequest.pipe(fs.createWriteStream(fileName));
newRequest.resume();
console.log(`Загружаем: ${imageUrl}`);
}
else
{
var message =
'\n********************************************************\n' +
'Ошибка загрузки файла ' + urlPrefix + imageUrl + '\n' +
'Код ошибки: ' + resp.statusCode + ' ' + resp.statusMessage + '; ' +
'Mime-type: ' + resp.headers['content-type'] + '\n' +
'********************************************************\n';
console.log(`${message}`);
newRequest.end();
}
});
newRequest.on('end', function()
{
console.log(`Загрузка завершена: ${imageUrl}`);
});
}
for(var page_counter = 1; page_counter < pageAmount; page_counter++)
{
var newRequest = request
(
'http://e-shuushuu.net/?page=' + page_counter,
function (error, response, body)
{
if (!error && response.statusCode == 200)
{
while(match = regExpImageURLWrapper.exec(body))
{
getCurrentImage(match[1]);
// break;
}
}
}
);
}
function my_func(ui){
//Чего-то делаем, к примеру:
alert(ui);
}
var data = [
{"i_id":"2223", "i_post":"qwerty", "i_descriptions": [
{"type":"html","value":"\r\n"},
{"type":"html","value":" "},
{"type":"html","value":"\u041a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0442\u0438\u0440\u0430\u0436\u0430 #48","color":"99ccff"},
{"type":"html","value":" "}
], "ui_status":"4", "ui_bid":"12414124125"},
{"i_id":"2228", "i_post":"qwerty", "i_descriptions": [
{"type":"html","value":"\r\n"},
{"type":"html","value":" "},
{"type":"html","value":"\u041a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0442\u0438\u0440\u0430\u0436\u0430 #48","color":"99ccff"},
{"type":"html","value":" "}
], "ui_status":"4", "ui_bid":"0"}
];
data.forEach(function(e){
var ubid = e.ui_bid;
+ubid&&my_func(ubid);
});
var data = JSON.parse('[{"ui_bid":"1451245124","ui_id":"124161616"},{"ui_bid":"124124124","ui_id":"123124"},{"ui_bid":"0","ui_id":"12123124"},{"ui_bid":"0","ui_id":"1231242352"}]');
data.forEach(function (item, value) {
var bid = +item.ui_bid;
if (bid) {
console.log(value); // Вот тут ваш запрос
}
});