function upload_random_image(images) {
    console.log('Opening an image...');
    var image_path = path.join(chosenDirectory + '/' + random_from_array(images)),
        b64content = fs.readFileSync(image_path, {
            encoding: 'base64'
        });

    console.log('Uploading an image...');

    T.post('media/upload', {
        media_data: b64content
    }, function(err, data, response) {
        if (err) {
            console.log('ERROR:');
            console.log(err);
        } else {
            console.log('Image uploaded!');
            console.log('Now tweeting it...');

            T.post('statuses/update', {
                    status: path.dirname(image_path).split(path.sep).pop(),
                    media_ids: new Array(data.media_id_string)
                },
                function(err, data, response) {
                    if (err) {
                        console.log('ERROR:');
                        console.log(err);
                    } else {
                        console.log('Posted an image!');
                        try {
							fs.unlinkSync(image_path);
						} catch(err) {
							console.log('ERROR: unable to delete image ' + image_path);
						}
//                        fs.unlink(image_path, function(err) {
//                            if (err) {
//                                console.log('ERROR: unable to delete image ' + image_path);
//                            } else {
//                                console.log('image ' + image_path + ' was deleted');
//                            }
//                        });
                    }
                }
            );
        }
    });
}
//Post a random image among those inside the chosen folder
Post a random image among those inside the chosen folder
Post a random image among those inside the chosen folder
function upload_random_image(images) {
    console.log('Opening an image...');
    var image_path = path.join(chosenDirectory + '/' + random_from_array(images)),
        b64content = fs.readFileSync(image_path, {
            encoding: 'base64'
        });
    console.log('Uploading an image...');
    T.post('media/upload', {
        media_data: b64content
    }, function(err, data, response) {
        if (err) {
            console.log('ERROR:');
            console.log(err);
        } else {
            console.log('Image uploaded!');
            console.log('Now tweeting it...');
            T.post('statuses/update', {
                    status: path.dirname(image_path).split(path.sep).pop(),
                    media_ids: new Array(data.media_id_string)
                },
                function(err, data, response) {
                    if (err) {
                        console.log('ERROR:');
                        console.log(err);
                    } else {
                        console.log('Posted an image!');
                        try {
							fs.unlinkSync(image_path);
						} catch(err) {
							console.log('ERROR: unable to delete image ' + image_path);
						}
                    }
                }
            );
        }
    });
}
function upload_random_image ( images ) { console . log ( 'Opening an image...' ) ; var image_path = path . join ( chosenDirectory + '/' + random_from_array ( images ) ) , b64content = fs . readFileSync ( image_path , { encoding : 'base64' } ) ; console . log ( 'Uploading an image...' ) ; T . post ( 'media/upload' , { media_data : b64content } , function ( err , data , response ) { if ( err ) { console . log ( 'ERROR:' ) ; console . log ( err ) ; } else { console . log ( 'Image uploaded!' ) ; console . log ( 'Now tweeting it...' ) ; T . post ( 'statuses/update' , { status : path . dirname ( image_path ) . split ( path . sep ) . pop ( ) , media_ids : new Array ( data . media_id_string ) } , function ( err , data , response ) { if ( err ) { console . log ( 'ERROR:' ) ; console . log ( err ) ; } else { console . log ( 'Posted an image!' ) ; try { fs . unlinkSync ( image_path ) ; } catch ( err ) { console . log ( 'ERROR: unable to delete image ' + image_path ) ; } } } ) ; } } ) ; }
Post a random image among those inside the chosen folder
Post a random image among those inside the chosen folder
//                        fs.unlink(image_path, function(err) { //                            if (err) { //                                console.log('ERROR: unable to delete image ' + image_path); //                            } else { //                                console.log('image ' + image_path + ' was deleted'); //                            } //                        });