Forum Discussion

VITHIKA's avatar
VITHIKA
Explorer | Level 3
8 years ago

Create a folder

I want to create a folder as soon as the user login in the app,

i tried the following function to create folder but i can see no folder is created..

I am calling this function after the login..

 
CreateFolder()
  {

    let args={
    "path": "/Homework/math",
    "autorename": false
}
  
     let headers = new Headers();
    headers.append('Authorization','Bearer'+this.accessToken);
    headers.append('Dropbox-API-Arg', JSON.stringify(args));
    headers.append('Content-Type', 'application/json');
    console.log("created folder");
    return this.http.post('https://api.dropboxapi.com/2-beta-2/files/create_folder',{headers:headers});

  }
}



 
dropboxlogin()
{
this.dropbox.login().then((success) => {
this.navCtrl.push(DropboxloginPage);
      this.dropbox.CreateFolder();
    this.showToast("folder created");
}, (err) => {
console.log(err);
});
 
}
 
  • Steve M.'s avatar
    Steve M.
    Icon for Dropbox Staff rankDropbox Staff
    What's the response from the server? Does the call succeed or fail? If it's failing, the response will probably tell you what's wrong.

    If I had to guess, it's `Bearer'+this.accessToken. You seem to be missing a space there... try 'Bearer '+this.accessToken instead.
      • VITHIKA's avatar
        VITHIKA
        Explorer | Level 3

        I made the changes,but still I cannot find any folder created..I am getting the toast as alert created,but when I am opening the dropbox,I cannot find the new folder created...

         

         
        CreateFolder()
          {
        
            let args={
            "path": "/invoice",
            "autorename": false
        }
           //this.dropbox.filesCreateFolder(args);
             let headers = new Headers();
            headers.append('Authorization','Bearer '+this.accessToken);
            headers.append('Dropbox-API-Arg', JSON.stringify(args));
            headers.append('Content-Type', 'application/json');
            console.log("created folder");
            return this.http.post('https://api.dropboxapi.com/2/files/create_folder_v2',{headers:headers});
        
          }
        }