Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var options = {
- host: 'google.com',
- port: 80,
- path: '/images/logos/ps_logo2.png'
- };
- var request = http.get(options);
- request.on('response', function (res) {
- res.on('data', function (chunk) {
- fs.writeFile(dir+'image.png', chunk, function (err) {
- if (err) throw err;
- console.log('It's saved!');
- });
- });
- });
- var http = require('http')
- , fs = require('fs')
- , options
- options = {
- host: 'www.google.com'
- , port: 80
- , path: '/images/logos/ps_logo2.png'
- }
- var request = http.get(options, function(res){
- var imagedata = ''
- res.setEncoding('binary')
- res.on('data', function(chunk){
- imagedata += chunk
- })
- res.on('end', function(){
- fs.writeFile('logo.png', imagedata, 'binary', function(err){
- if (err) throw err
- console.log('File saved.')
- })
- })
- })
- var fs = require('fs');
- var request = require('request');
- // Or with cookies
- // var request = require('request').defaults({jar: true});
- request.get({url: 'https://someurl/somefile.torrent', encoding: 'binary'}, function (err, response, body) {
- fs.writeFile("/tmp/test.torrent", body, 'binary', function(err) {
- if(err)
- console.log(err);
- else
- console.log("The file was saved!");
- });
- });
- var http = require('http-request');
- var options = {url: 'http://localhost/foo.pdf'};
- http.get(options, '/path/to/foo.pdf', function (error, result) {
- if (error) {
- console.error(error);
- } else {
- console.log('File downloaded at: ' + result.file);
- }
- });
- var http = require('http'),
- fs = require('fs'),
- options;
- options = {
- host: 'www.google.com' ,
- port: 80,
- path: '/images/logos/ps_logo2.png'
- }
- var request = http.get(options, function(res){
- //var imagedata = ''
- //res.setEncoding('binary')
- var chunks = [];
- res.on('data', function(chunk){
- //imagedata += chunk
- chunks.push(chunk)
- })
- res.on('end', function(){
- //fs.writeFile('logo.png', imagedata, 'binary', function(err){
- var buffer = Buffer.concat(chunks)
- fs.writeFile('logo.png', buffer, function(err){
- if (err) throw err
- console.log('File saved.')
- })
- })
- const subscriptionKey = 'your_azure_subscrition_key';
- const uriBase = // **MUST change your location (mine is 'eastus')**
- 'https://eastus.api.cognitive.microsoft.com/vision/v2.0/analyze';
- // Request parameters.
- const params = {
- 'visualFeatures': 'Categories,Description,Adult,Faces',
- 'maxCandidates': '2',
- 'details': 'Celebrities,Landmarks',
- 'language': 'en'
- };
- const options = {
- uri: uriBase,
- qs: params,
- body: fs.readFileSync(./my_local_image_path.jpg),
- headers: {
- 'Content-Type': 'application/octet-stream',
- 'Ocp-Apim-Subscription-Key' : subscriptionKey
- }
- };
- request.post(options, (error, response, body) => {
- if (error) {
- console.log('Error: ', error);
- return;
- }
- let jsonString = JSON.stringify(JSON.parse(body), null, ' ');
- body = JSON.parse(body);
- if (body.code) // err
- {
- console.log("AZURE: " + body.message)
- }
- console.log('Responsen' + jsonString);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement