搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目