dbx_platform 1.1.7+9 copy "dbx_platform: ^1.1.7+9" to clipboard
dbx_platform: ^1.1.7+9 copied to clipboard

An unofficial dropbox platform package.

dbx_platform #

unofficial Dropbox client
Hecho en 🇵🇷 por Radamés J. Valentín Reyes

Important notes #

  • File System paths on DropBox Platform must always start with a "/"
  • Note: dbx_directory must have a "/" on the right of the folder name(end of the path) in order for "Download entire folder as .zip" function to work properly

Getting an API key and other required info #

Step 1 #

Tap/click the image below to visit the Dropbox developer website and tap the button that says "App console" on the top right corner. Login or create an account if necessary.

Dropbox developer website

Step 2 #

Create app page

Step 3 #

Make selections from the given options and tap/click on Create app button

Make selections from the given options

Step 4 #

Enable permissions from the app page on the developer console. You need read and write permissions enabled so that your API calls don't throw an error.

Permissions

Step 5 #

Generate an access token. Go to the Settings tab of your app to generate the access token, copy the app key and app secret for later use.

Token generation


Import the dart package #

import 'package:dbx_platform/dbx_platform.dart';
import 'dart:io';

Dropbox instance #

DBX dbx = DBX(
  accessToken: accessToken, 
  appKey: appKey,
  appSecret: appSecret,
);

Functions(performs the API calls) #

Create folder/directory #

Creates a directory on the specified path.

await dbx.createFolder(
  folderToCreate: DBX_Directory(
    path: "/test",
  ),
);

Delete DBX_Item #

Deletes the specified item. Can delete both DBX_File and DBX_Directory.

await dbx.deleteItem(
  dbx_item: DBX_Directory(
	path: "/test",
  ),
);

DBX_Item Exists #

Returns a Boolean value telling whether or not the specified item exists.

await dbx.itemExists(
  dbx_item: DBX_Directory(
	path: "/test",
  ),
);

Upload file/Create file #

Creates a file on dropbox and saves the byte data from the specified local file into the created DBX_File on the cloud. If the file exists it can be overwriten by changing the mode.

await dbx.createFile(
  fileToUpload: File("./test_assets/test.odt"), 
  fileToCreate: DBX_File(
    path: "/test.odt",
  ), 
  mode: WriteMode.add,
  mute: true,
);

Read file as bytes (download file) #

Returns a list of bytes if the file exists

List<int> bytes = await dbx.readFileAsBytes(
  dbx_file: DBX_File(path: "/test.odt"),
);
File file = File("test_files/test.odt");
file.createSync(recursive: true);
file.writeAsBytesSync(bytes);

Read file as String #

Returns the file content as a string if the file exists

String stringContent = await dbx.readFileAsString(
  dbx_file: DBX_File(path: "/test.odt"),
);

Get item metadata #

Returns the item metadata if the item exists. Returns null if it does not.

DBX_Item_Metadata? dbx_item_metadata = await dbx.itemMetadata(
  dbx_item: DBX_File(path: "/test.odt"),
);
if(dbx_item_metadata != null){
  print(dbx_item_metadata.name);
  print("Modified by client on : ${dbx_item_metadata.client_modified.toString()}");
  print("File size: ${dbx_item_metadata.size}");
}

List folder/directory contents #

Get a list of all of the items within a folder/directory

await dbx.list(
  dbx_directory: DBX_Directory(path: "/database"),
);

Download entire folder as .zip #

Downloads a DBX_Directory as a .zip and saves it to the desired output file location

await dbx.downloadEntireFolderAsZip(
  dbx_directory: DBX_Directory(path: "/database/"), 
  output: File("test_database/entireFolder.zip"),
),

Get thumbnail #

Generates and returns a thumbnail of the specified image

List<int> bytes = await dbx.getThumbnail(
  image: dropboxFile,
  format: ThumbnailFormat.png,
);

Create file from memory #

Creates a file and saves in it the bytes that you suply from your memory

await dbx.createFileFromMemory(
  bytes: bytes, 
  fileToCreate: dbx_file, 
  mode: WriteMode.add,
);
SearchResults searchResults = await dbx.search(searchQuery: "file full of metadata");

Search continue #

await dbx.searchContinue(
  cursor: "cursor from the previous search",
);

Note #

Must choose Full Dropbox access in order to avoid getting an error when using the tag functions. I don't know why but unfortunately that's how it works(or at least in April 29 2022 9am UTC-4). Full Dropbox Access screen

Add tag #

Adds a certain tag to a file

await dbx.addTag(
  dbx_file: fileFullOfTags, 
  tag_text: "Hello",
);

Remove Tag #

Removes the specified tag from the specified file

await dbx.removeTag(
  dbx_file: fileFullOfTags, 
  tag_text: "Hello",
);

Get tags #

Retrieves the tags asociated with the files sent as parameters and adds them to the corresponding files.

List<DBX_File> filesWithTags = await dbx.getTags(files: []);

Full Examples #

Example 1 #

Creating files and folders and listing a folder's contents

//Create 2 folders. database and something_cool inside of database
await dbx.createFolder(
  folderToCreate: DBX_Directory(path: "/database/something_cool"),
);
//Create a file inside the database folder
await dbx.createFile(
  fileToUpload: File("test_database/test.odt"), 
  fileToCreate: DBX_File(path: "/database/test.odt"), 
  mode: WriteMode.add,
);
//List all database folder contents
List<DBX_Item> items = await dbx.list(
  dbx_directory: DBX_Directory(path: "/database"),
);
//Print the list
print(items);

Example 2 #

Uploading an image file, downloading and saving a thumbnail.

//Create a test
DBX_File dropboxFile = DBX_File(path: "/images/logo.png");
File localImage = File("test_assets/logo.png");
await dbx.createFile(
  fileToUpload: localImage, 
  fileToCreate: dropboxFile, 
  mode: WriteMode.add,
);
List<int> bytes = await dbx.getThumbnail(
  image: dropboxFile,
  format: ThumbnailFormat.png,
);
File output = File("test_database/logo.png");
await output.create(recursive: true);
await output.writeAsBytes(bytes);

Example 3 #

Create a file

Map<String,dynamic> object = {
  "nombre" : "alguien",
};
String json = jsonEncode(object);
DBX_File dbx_file = DBX_File(path: "/algo.json");
await dbx.createFileFromMemory(
  bytes: json.codeUnits, 
  fileToCreate: dbx_file, 
  mode: WriteMode.add,
);

Example 4 #

Metadata

DBX_File fileFullOfMetadata = DBX_File(path: "/fileFullOfMetadata.txt");
//Create file
await dbx.createFileFromMemory(
  bytes: "Hello World".codeUnits, 
  fileToCreate: fileFullOfMetadata, 
  mode: WriteMode.overwrite,
);
//Add tag
await dbx.addTag(
  dbx_file: fileFullOfMetadata, 
  tag_text: "Hello",
);
//Get files with their respective tags
List<DBX_File> filesWithTags = await dbx.getTags(files: [
  fileFullOfMetadata,
]);
print(filesWithTags.first.tags!.first.tag_text);
DBX_File fileFullOfMetadata = DBX_File(path: "/fileFullOfMetadata.txt");
await dbx.removeTag(
  dbx_file: fileFullOfMetadata, 
  tag_text: "Hello",
);
//Get files with their respective tags
List<DBX_File> filesWithTags = await dbx.getTags(files: [
  fileFullOfMetadata,
]);
print(filesWithTags);

Example 5 #

Search

SearchResults searchResults = await dbx.search(searchQuery: "file full of metadata");
print(searchResults.items);

Contribute/donate by tapping on the Pay Pal logo/image #


References #

0
likes
120
pub points
33%
popularity

Publisher

unverified uploader

An unofficial dropbox platform package.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

sexy_api_client

More

Packages that depend on dbx_platform