onedrive_rest_api 0.0.1
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