Cliente do Dropbox para Flutter. A biblioteca suporta Android e iOS. A autorização é feita por meio do aplicativo Dropbox ou de um navegador da web externo.
Orientação gerada a partir de informações públicas. Apenas para referência.
Um pacote Flutter que fornece um cliente para interagir com a API do Dropbox, permitindo o gerenciamento de arquivos e pastas no Dropbox em aplicativos para Android e iOS. Ele suporta autenticação por meio do aplicativo Dropbox ou de um navegador web externo, garantindo acesso seguro às contas dos usuários. A biblioteca foi projetada para integração perfeita em aplicações móveis que exigem funcionalidade de armazenamento em nuvem. Simplifica operações comuns como upload, download e listagem de arquivos, tornando-a ideal para desenvolvedores que criam aplicativos multiplataforma com conectividade ao Dropbox.
Casos de uso
Backup e sincronização de arquivos
Armazenamento de documentos em nuvem
Gerenciamento de arquivos do usuário
Persistência de dados do aplicativo
Integração com fluxos de trabalho do Dropbox
Principais recursos
Suporta Android e iOS
Autenticação por meio do aplicativo Dropbox ou navegador
Upload/download de arquivo simples
Compatibilidade multiplataforma
Autorização OAuth2 segura
Indicado para
Aplicativos móveis que precisam de armazenamento em nuvem
Aplicativos que exigem acesso ao arquivo do usuário
Desenvolvedores usando o Dropbox como backend
Projetos Flutter com necessidades de nuvem
Aplicativos direcionados tanto para Android quanto para iOS
Considerações
Requer aplicativo ou navegador do Dropbox para autenticação
Limitado ao ecossistema do Dropbox
Necessita de tratamento adequado de erros para problemas de rede
Depende da estabilidade da API externa do Dropbox
Pode ser necessário consentimento do usuário para acesso ao arquivo
README original
Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.
dropbox client
A flutter plugin for accessing Dropbox.
Setup
Register a Dropbox API app from https://www.dropbox.com/developers .
You need a Dropbox app key. Public clients using PKCE do not need an app secret,
and must not embed one in the application.
For Android, add below in AndroidManifest.xml (replace DROPBOXKEY with your key)
<activity
android:name="com.dropbox.core.android.AuthActivity"
android:configChanges="orientation|keyboard"
android:launchMode="singleTask">
<intent-filter>
<!-- Change this to be db- followed by your app key -->
<data android:scheme="db-DROPBOXKEY" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
If you need more help setting up Android, please read https://github.com/dropbox/dropbox-sdk-java#setup .
3.a) If you are using Swift, add below code to AppDelegate.swift
import ObjectiveDropboxOfficial
// should be inside AppDelegate class
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if let authResult = DBClientsManager.handleRedirectURL(url) {
if authResult.isSuccess() {
print("dropbox auth success")
} else if (authResult.isCancel()) {
print("dropbox auth cancel")
} else if (authResult.isError()) {
print("dropbox auth error \(authResult.errorDescription)")
}
}
return true
}
// if your are linked with ObjectiveDropboxOfficial 6.x use below code instead
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
DBClientsManager.handleRedirectURL(url, completion:{ (authResult) in
if let authResult = authResult {
if authResult.isSuccess() {
print("dropbox auth success")
} else if (authResult.isCancel()) {
print("dropbox auth cancel")
} else if (authResult.isError()) {
print("dropbox auth error \(authResult.errorDescription)")
}
}
});
return true
}
3.b) If you are using Objective C, add below code to AppDelegate.m
#import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
DBOAuthResult *authResult = [DBClientsManager handleRedirectURL:url];
if (authResult != nil) {
if ([authResult isSuccess]) {
NSLog(@"Success! User is logged into Dropbox.");
} else if ([authResult isCancel]) {
NSLog(@"Authorization flow was manually canceled by user!");
} else if ([authResult isError]) {
NSLog(@"Error: %@", authResult);
}
}
return NO;
}
// if your are linked with ObjectiveDropboxOfficial 6.x use below code instead
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL result = [DBClientsManager handleRedirectURL:url completion: ^(DBOAuthResult *authResult) {
if (authResult != nil) {
if ([authResult isSuccess]) {
NSLog(@"Success! User is logged into Dropbox.");
} else if ([authResult isCancel]) {
NSLog(@"Authorization flow was manually canceled by user!");
} else if ([authResult isError]) {
NSLog(@"Error: %@", authResult);
}
}
}];
return NO;
}
Update Deployment Target to iOS 9.0 or above from Xcode. (dropbox_client 0.7.0 and above)
Add below permissions to your app from Dropbox App Console:
files.metadata.read
files.metadata.write
files.content.read
files.content.write
If you need more help setting up for iOS, please read https://github.com/dropbox/dropbox-sdk-obj-c#get-started .
Usage
import'package:dropbox_client/dropbox_client.dart';
FutureinitDropbox() async {
// Initialize a public client for PKCE. Call only once.awaitDropbox.init(dropbox_clientId, dropbox_key);
}
The optional third argument is retained for legacy confidential-client flows:
// Legacy AuthorizationString accessToken;
FuturetestLogin() async {
// this will run Dropbox app if possible, if not it will run authorization using a web browser.awaitDropbox.authorize();
}
FuturegetAccessToken() async {
accessToken = awaitDropbox.getAccessToken();
}
FutureloginWithAccessToken() async {
awaitDropbox.authorizeWithAccessToken(accessToken);
}
FuturetestLogout() async {
// unlink removes authorizationawaitDropbox.unlink();
}
// OAuth 2 code flow with PKCE that grants a short-lived tokenString credentials;
FuturetestLogin() async {
// this will run Dropbox app if possible, if not it will run authorization using a web browser.awaitDropbox.authorizePKCE();
}
FuturegetCredentials() async {
credentials = awaitDropbox.getCredentials();
}
FutureloginWithCredentials() async {
awaitDropbox.authorizeWithCredentials(credentials);
}
FuturetestLogout() async {
// unlink removes authorizationawaitDropbox.unlink();
}
// List / Upload / DownloadFuturetestListFolder() async {
final result = awaitDropbox.listFolder(''); // list root folderprint(result);
final url = awaitDropbox.getTemporaryLink('/file.txt');
print(url);
}
FuturetestUpload() async {
final filepath = '/path/to/local/file.txt';
final result = awaitDropbox.upload(filepath, '/file.txt', (uploaded, total) {
print('progress $uploaded / $total');
});
}
FuturetestDownload() async {
final filepath = '/path/to/local/file.txt';
final result = awaitDropbox.download('/dropbox_file.txt', filepath, (downloaded, total) {
print('progress $downloaded / $total');
});
}