搜尋套件、儲存庫與 APP 分類

套件詳情v0.23.1

cloudinary_public

此套件可讓您直接將媒體檔案上傳至 Cloudinary,無需暴露您的 apiKey 或 secretKey。

AndroidiOSmacOSWindowsLinux
近 30 天下載
3780
喜歡數
128
Pub 分數
150

安裝套件

flutter pub add cloudinary_public

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

cloudinary_public 套件允許從 Flutter 應用程式直接將媒體上傳至 Cloudinary,無需揭露敏感的 API 金鑰。它透過使用未簽名的上傳預設安全地處理驗證,讓客戶端可以直接上傳檔案,同時維持伺服器端的安全性。非常適合需要使用者產生內容的應用程式,例如照片分享或個人頭像上傳。此套件支援多個平台,包括 Android、iOS、macOS、Windows 和 Linux。

適用情境

  • 從移動應用程式直接上傳檔案
  • 使用者產生的內容儲存
  • 個人檔案圖片上傳
  • 影像和影片管理
  • 安全的媒體處理,無需暴露憑據

主要特色

  • 無 API 金鑰暴露
  • 支援無簽名上傳預設
  • 跨平台相容性
  • 與 Cloudinary 的簡單整合
  • 實時上傳進度追蹤

適合對象

  • 行動應用程式中的媒體上傳
  • 需要安全文件傳輸的應用程式
  • 開發者避免後端認證
  • 使用 Cloudinary 進行媒體存儲的項目
  • 僅前端媒體處理

使用建議

  • 需要設定 Cloudinary 上傳預設
  • 限制為無簽名上傳
  • 依賴 Cloudinary 的免費層級或付費方案
  • 不適用於私人或受限媒體
  • 必須正確配置 Cloudinary 儀表板

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

cloudinary_public

Build Status Coverage Status

This package allows you to upload media files directly to cloudinary, without exposing your apiKey or secretKey.

Getting started

Add the dependency cloudinary_public: ^0.23.1 to your project:

import 'package:cloudinary_public/cloudinary_public.dart';

final cloudinary = CloudinaryPublic('CLOUD_NAME', 'UPLOAD_PRESET', cache: false);

Check https://cloudinary.com/documentation/upload_images#unsigned_upload on how to create an upload preset.

Using Image Picker Plugin
var image = await ImagePicker.pickImage(source: ImageSource.camera);

try {
    CloudinaryResponse response = await cloudinary.uploadFile(
        CloudinaryFile.fromFile(image.path, resourceType: CloudinaryResourceType.Image),
    );
    
    print(response.secureUrl);
} on CloudinaryException catch (e) {
  print(e.message);
  print(e.request);
}
Using Multi Image Picker Plugin
final images = await MultiImagePicker.pickImages(maxImages: 4);

List<CloudinaryResponse> uploadedImages = await cloudinary.multiUpload(
images
    .map(
      (image) => CloudinaryFile.fromFutureByteData(
        image.getByteData(),
        identifier: image.identifier,
      ),
    )
    .toList(),
);

print(uploadedImages[0].secureUrl);

Image Transformation

// CloudinaryImage
final cloudinaryImage = CloudinaryImage('https://res.cloudinary.com/demo/image/upload/front_face.png');
// or using the image public id
final cloudinaryImage = cloudinary.getImage('front_face');

final String url = cloudinaryImage.transform().width(150).height(150).gravity('face').crop('thumb').generate();
// or using the shortcut
final String url = cloudinaryImage.thumbnail(width: 150, height: 150).generate();


// Chain example
final url = cloudinaryImage.transform()
    .width(150)
    .height(150)
    .gravity('face')
    .crop('thumb')
    .chain()
    .radius(20)
    .chain()
    .effect('sepia')
    .chain()
    .overlay(cloudinary.getImage('cloudinary_icon'))
    .gravity('south_east')
    .x(5)
    .y(5)
    .width(50)
    .opacity(60)
    .effect('brightness:200')
    .chain()
    .angle(10)
    .generate();
// generates
// https://res.cloudinary.com/demo/image/upload/c_thumb,g_face,h_150,w_150/r_20/e_sepia/e_brightness:200,g_south_east,l_cloudinary_icon,o_60,w_50,x_5,y_5/a_10/front_face.png

Upload Progress

final res = await cloudinary.uploadFile(
  CloudinaryFile.fromFile(
    _pickedFile.path,
    folder: 'hello-folder',
    context: {
      'alt': 'Hello',
      'caption': 'An example image',
    },
  ),
  onProgress: (count, total) {
    setState(() {
      _uploadingPercentage = (count / total) * 100;
    });
  },
);

Upload In Chunks

Use chunked upload when file size is more then 100 Megabytes.

By default, the chunk size is set to 20 Megabytes but can be set to as low as 5 Megabytes by using the chunk_size parameter.

Source: https://cloudinary.com/documentation/upload_images#chunked_asset_upload

final res = await cloudinary.uploadFileInChunks(
  CloudinaryFile.fromFile(
    _pickedFile.path,
    folder: 'hello-folder',
    context: {
      'alt': 'Hello',
      'caption': 'An example upload in chunks',
    },
  ),
  chunkSize: 10000000
  onProgress: (count, total) {
    setState(() {
      _uploadingPercentage = (count / total) * 100;
    });
  },
);

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案