Tuesday 23 May 2017

How Can I Upload Using Node Request Module On Imageshack?

I know there's a nodemodule for that. For some reason, I got this error saying that it can't read the file, altough I'm pretty sure path is correct. This is the API return I get:

The file uploaded is not being detected as an image file imageshack

var util = require('./util');

var fs = require('fs'); var request = require('request');

module.exports = {

uploadImagem: function() {

var file = fs.createReadStream("./api/teste.jpg");

var authOptions = {
  url: 'https://api.imageshack.com/v2/user/login',
  form: {
    user: user,
    password: pass,
    token: token
  }
}

request.post(authOptions, function(err, AuthResponse, authBody) {
  var apiAuthResponse = JSON.parse(authBody);
  //console.log(apiResponse.result);

  var imageOptions = {
    url: 'https://api.imageshack.com/v2/images',
    form: {
      file: file,
      api_key: authOptions.form.token,
      auth_token: apiAuthResponse.auth_token
    }
  }

  request.post(imageOptions, function(err, UploadResponse, uploadBody) {
    var apiUploadResponse = JSON.parse(uploadBody);
    console.log(UploadResponse.body);
  });
});

} }



via Vinicius Guerrero

No comments:

Post a Comment