简体   繁体   中英

Read and Writing Files Dropbox API V2

I am try to read and write to a file on my Dropbox using the new Drobox API, I have already created a variable that can access my account and have been able to list the contents of my Dropbox, but so far I have not been able to get a specific files contents. What I recieve in the console output is,

todocl.file - The file path, which is 'Test.txt' (I have tried '/Test.txt', that just gives a 409 error, path not found.)

and

Dropbox-sdk.min.js:8 Uncaught DOMException: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'blob').

function readFiles() {
    todocl.dbx.filesDownload({
        path: '/Help.txt'
    }).then(function (response) {
        var text = response.fileBlob;
        var reader = new FileEventListener("loadend", function () {
            console.log(reader.result);
        });
        reader.readAsText(text);
    }).catch(function (error) {
        console.error(error);
    });
}

Dropbox Api http://dropbox.github.io/dropbox-sdk-js/Dropbox.html

Any help would be great!

Turns out I needed the root for the file path and the corretc setu for the filee reader.

function readFiles() {
    todocl.dbx.filesDownload({
        path: todocl.file
    }).then(function (data) {
        var blob = data.fileBlob;
        var reader = new FileReader()
        reader.addEventListener("loadend", function () {
            console.log(reader.result);
        })
        reader.readAsText(blob);
    }).catch(function (error) {
        console.error(error);
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM