Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

angularjs - upload file to dropBox using /files_put javascript

Is it possible to upload a local file to dropbox using http put method ? i am uploading a file but it is without body ? ( "bytes": 0 )

how can i add a content to my file ?

my code is the following :

    $scope.uploadHtmlFile = function() {
    $http({
        method: 'PUT',
        url: 'https://api-content.dropbox.com/1/files_put/dropbox/test.txt?access_token='+ localStorage.getItem('accessToken')
    }).success(function(data,status,headers,config){
        console.log(data);
        console.log('file uploaded successfully');
    }).error(function(data,status,headers,config){

    });
}

my file is successfully uploaded but with no content ? it is empty !! the documentation is a little confusing to me : https://www.dropbox.com/developers/core/docs#files_put

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

@smarx : i was making an empty HTTP PUT request, and i ended up by solving my issue this way:

$scope.uploadHtmlFile = function() {
    var data = "This is a file upload test ";

    $http({
        method: 'PUT',
        url: 'https://api-content.dropbox.com/1/files_put/dropbox/test.html?access_token=' + localStorage.getItem('accessToken'),
        data: data
    }).success(function(data, status, headers, config) {
        console.log(data);
        console.log('file uploaded successfully');
    }).error(function(data, status, headers, config) {

    });
}

thanks for your feedback !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...