onedrive_rest_api 0.0.1 copy "onedrive_rest_api: ^0.0.1" to clipboard
onedrive_rest_api: ^0.0.1 copied to clipboard

A Dart client for the OneDrive API that provides easy access to OneDrive's file operations including upload, download, copy, move, and more.

๐Ÿ“‚ OneDriveApi #

A Dart package that provides convenient access to the OneDrive API, built on top of oauth2restclient.


โœจ Features #

  • ๐Ÿ” OAuth2 authentication via oauth2restclient
  • ๐Ÿ“„ List, upload, download, copy, move, and delete OneDrive files
  • ๐Ÿ—‚ List and create folders
  • ๐Ÿ’ก Easy access to OneDrive Streams and metadata
  • ๐Ÿ“ Supports both personal and business OneDrive
  • ๐Ÿ›ค Path-based API for intuitive file operations

๐Ÿ“ฆ Installation #

Add to your pubspec.yaml:

dependencies:
  one_drive_api: ^0.0.1

๐Ÿš€ Getting Started #

import 'package:one_drive_api/one_drive_api.dart';

void main() async {
  final account = OAuth2Account();

  // OneDrive์šฉ OAuth2 provider ๋“ฑ๋ก
  account.addProvider(OneDrive(
    clientId: "YOUR_CLIENT_ID",
    redirectUri: "YOUR_REDIRECT_URI",
    scopes: [
      "User.Read",
      "Files.ReadWrite.All",
      "Files.Read.All",
      "openid",
      "email",
      "offline_access",
    ],
  ));

  // ๋กœ๊ทธ์ธ ๋˜๋Š” ํ† ํฐ ๋กœ๋“œ
  final token = await account.newLogin("onedrive");
  final client = await account.createClient(token);

  // API ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
  final onedrive = OneDriveRestApi(client);

  // ๋“œ๋ผ์ด๋ธŒ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ
  final drive = await onedrive.getDrive();
  print("Drive ID: ${drive.id}");

  // ๋ฃจํŠธ ํด๋” ํŒŒ์ผ ๋ชฉ๋ก ์กฐํšŒ
  final items = await onedrive.listChildren("/");

  for (final item in items.value) {
    print("${item.name} (${item.id})");
  }
}

๐Ÿ“‚ Example Operations #

  • List Files:
// ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด์šฉ ์กฐํšŒ
await onedrive.listChildren("/", top: 20);

// ํŠน์ • ํด๋” ๋‚ด์šฉ ์กฐํšŒ
await onedrive.listChildren("/Documents", top: 20);
  • Upload File:
// ๋ฃจํŠธ์— ํŒŒ์ผ ์—…๋กœ๋“œ
await onedrive.upload("/example.txt", fileStream);

// ํŠน์ • ํด๋”์— ํŒŒ์ผ ์—…๋กœ๋“œ
await onedrive.upload("/Documents/report.pdf", fileStream);
  • Create Folder:
// ๋ฃจํŠธ์— ํด๋” ์ƒ์„ฑ
await onedrive.createFolder("/", 'New Folder');

// ํŠน์ • ํด๋” ์•ˆ์— ํ•˜์œ„ ํด๋” ์ƒ์„ฑ
await onedrive.createFolder("/Documents", 'Work');
  • Download File:
// ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ
final stream = await onedrive.download("/Documents/file.txt");
  • Copy File:
// ํŒŒ์ผ ๋ณต์‚ฌ
await onedrive.copy("/Documents/file.txt", "/Backup");
  • Move/Rename File:
// ํŒŒ์ผ ์ด๋™
await onedrive.move("/Documents/file.txt", "/Pictures");

// ํŒŒ์ผ ์ด๋™ํ•˜๋ฉด์„œ ์ด๋ฆ„ ๋ณ€๊ฒฝ
await onedrive.move("/Documents/file.txt", "/Pictures", "new_name.txt");
  • Delete File:
// ํŒŒ์ผ ์‚ญ์ œ
await onedrive.delete("/Documents/file.txt");

// ํด๋” ์‚ญ์ œ
await onedrive.delete("/Documents/Old Folder");

๏ฟฝ๏ฟฝ Path-based API #

์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์ง๊ด€์ ์ธ ๊ฒฝ๋กœ ๊ธฐ๋ฐ˜ API๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค:

  • ์ ˆ๋Œ€ ๊ฒฝ๋กœ: /๋กœ ์‹œ์ž‘ํ•˜๋Š” ๊ฒฝ๋กœ (์˜ˆ: /Documents/file.txt)
  • ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ: /๋Š” OneDrive์˜ ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค
  • ํด๋” ๊ฒฝ๋กœ: /Documents, /Pictures ๋“ฑ
  • ํŒŒ์ผ ๊ฒฝ๋กœ: /Documents/report.pdf, /Pictures/photo.jpg ๋“ฑ

๊ฒฝ๋กœ ์˜ˆ์ œ #

// ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ
"/"

// ํด๋”
"/Documents"
"/Pictures"
"/Documents/Work"

// ํŒŒ์ผ
"/Documents/file.txt"
"/Pictures/photo.jpg"
"/Documents/Work/report.pdf"

๐Ÿ”— Dependencies #


๐Ÿ“„ License #

MIT License ยฉ Heebaek Choi

0
likes
150
points
14
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

A Dart client for the OneDrive API that provides easy access to OneDrive's file operations including upload, download, copy, move, and more.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, oauth2restclient

More

Packages that depend on onedrive_rest_api