使用angularjs将文件上传到Dropbox

时间:2015-12-14 04:56:06

标签: angularjs dropbox

我正在尝试使用以下代码将文件上传到Dropbox。文件已成功上传到Dropbox,但大小已超过0个字节。

我现在正计划上传microsoft word和pdf文件。

    $scope.uploadHtmlFile = function($files) {
        var data = $files;
        $http({
            method: 'PUT',
            url: 'https://api-content.dropbox.com/1/files_put/dropbox/' + $files[0].name + '?access_token=TOKEN',
            data: data
        }).success(function(data, status, headers, config) {
            console.log(data);
            console.log('file uploaded successfully');
        }).error(function(data, status, headers, config) {
            console.log('error : ' + data);
            console.log('erro file uploaded successfully');
        });
    }

1 个答案:

答案 0 :(得分:0)

$ files是一个数组对象,文件将使用$ files [0]引用。

$scope.uploadHtmlFile = function($files) {
        var data = $files[0];
        $http({
            method: 'PUT',
            url: 'https://api-content.dropbox.com/1/files_put/dropbox/' + $files[0].name + '?access_token=TOKEN',
            data: data
        }).success(function(data, status, headers, config) {
            console.log(data);
            console.log('file uploaded successfully');
        }).error(function(data, status, headers, config) {
            console.log('error : ' + data);
            console.log('erro file uploaded successfully');
        });
    }