node js使用通配符文件名上传文件

时间:2017-06-17 06:00:21

标签: node.js wildcard soundcloud

我在我的艺术家文件夹中有一个名为 artist_12.mp3

的文件

但我无法使用通配符格式的脚本上传文件

addTrack.js

1 个答案:

答案 0 :(得分:0)

'use strict';
var soundcloudnodejs = require('soundcloudnodejs');
var fs = require('fs');

var credentials = require('credentials');

var options = {
    client_id: process.env.client_id || credentials.client_id,
    client_secret: process.env.client_secret || credentials.client_secret,
    grant_type: process.env.grant_type || credentials.grant_type,
    redirect_uri: process.env.redirect_uri || credentials.redirect_uri,
    username: process.env.username || credentials.username,
    password: process.env.password || credentials.password
};

soundcloudnodejs.getToken(options).then(function (token) {

    if (!token || !token.access_token) {
        console.log('getToken err: undefined token.access_token ');
    } else {
        var track = {
            title: 'dog_example',
            description: 'dog_example',
            genre: 'dog_example',
            artwork_data: __dirname + '/artist/artist.jpeg',
            sharing: 'public',
            oauth_token: token.access_token,
            asset_data: __dirname + '/artist/artist_*.mp3'
        };

        soundcloudnodejs.addTrack(track, function (err, track) {
            if (err) {
                console.log(err)
            }
            console.log(track);
        });
    }

});