upload file to dropBox using /files_put javascript

落花浮王杯 提交于 2019-12-18 08:54:19

问题


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


回答1:


@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 !




回答2:


I don't see anywhere in your HTTP call where you're actually passing a body. It seems like you're making an empty PUT request?

(Or maybe there's just something here about AngularJS that I don't understand, and you're adding a body somewhere else?)



来源:https://stackoverflow.com/questions/22101651/upload-file-to-dropbox-using-files-put-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!