onedrive_rest_api 0.0.2 copy "onedrive_rest_api: ^0.0.2" to clipboard
onedrive_rest_api: ^0.0.2 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.

πŸ“‚ OneDriveRestApi #

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:
  onedrive_rest_api: ^0.0.2

πŸš€ Getting Started #

import 'package:onedrive_rest_api/onedrive_rest_api.dart';

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

  // Microsoft OAuth2 provider 등둝
  account.addProvider(Microsoft(
    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("microsoft");
  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/file.txt");

// 파일 볡사 (λ‹€λ₯Έ 이름)
await onedrive.copy("/Documents/file.txt", "/Backup/file_copy.txt");
// ⚠️ λ³΅μ‚¬λŠ” 비동기 μž‘μ—…μž…λ‹ˆλ‹€. 볡사 μ™„λ£ŒκΉŒμ§€ μ‹œκ°„μ΄ 걸릴 수 μžˆμŠ΅λ‹ˆλ‹€.
  • Move/Rename File:
// 파일 이동 (같은 이름)
await onedrive.move("/Documents/file.txt", "/Pictures/file.txt");

// 파일 μ΄λ™ν•˜λ©΄μ„œ 이름 λ³€κ²½
await onedrive.move("/Documents/file.txt", "/Pictures/new_name.txt");

// 같은 ν΄λ”μ—μ„œ μ΄λ¦„λ§Œ λ³€κ²½
await onedrive.move("/Documents/file.txt", "/Documents/new_name.txt");
  • Delete File:
// 파일 μ‚­μ œ
await onedrive.delete("/Documents/file.txt");

// 폴더 μ‚­μ œ
await onedrive.delete("/Documents/Old Folder");

πŸ›€ Path-based API #

  • λͺ¨λ“  μ£Όμš” ν•¨μˆ˜λŠ” 경둜(path)만 λ°›μŠ΅λ‹ˆλ‹€. (ID 기반 μ•„λ‹˜)
  • 루트둜 볡사/이동/생성 μ‹œ κ²½λ‘œλŠ” / λ˜λŠ” ""(빈 λ¬Έμžμ—΄)둜 μ²˜λ¦¬ν•˜λ©΄ λ©λ‹ˆλ‹€.
  • copy/moveλŠ” λ°˜ν™˜κ°’μ΄ μ—†μœΌλ©°, copyλŠ” 비동기 μž‘μ—…μ΄λ―€λ‘œ λ°”λ‘œ 볡사본이 보이지 μ•Šμ„ 수 μžˆμŠ΅λ‹ˆλ‹€.

경둜 예제 #

// 루트 디렉토리
"/"

// 폴더
"/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