Upload file to dropBox using / files _put javascript

Can I upload a local file to Dropbox using the http put method? I upload a file, but is it without a body? ("bytes": 0)

How can I add content to my file?

my code is as follows:

    $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 uploaded successfully, but without content? he is empty! the documentation is a bit confusing to me: https://www.dropbox.com/developers/core/docs#files_put

+4
source share
2 answers

@smarx: I made an empty HTTP PUT request, and in the end I decided to solve this problem as follows:

$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) {

    });
}

Thank you for your feedback!

+5
source

HTTP-, . , PUT?

(, , - AngularJS, , - ?)

+2

Source: https://habr.com/ru/post/1529457/


All Articles