Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Blob Creation as Path in flutter_file_picker #1665

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vicajilau
Copy link

@vicajilau vicajilau commented Dec 31, 2024

Pull Request: Add Blob Creation as Path in flutter_file_picker

Description

This PR introduces the capability to create a blob from the picked file and set it as the path in the flutter_file_picker plugin. This change allows for better handling of file data directly as URLs, enhancing the flexibility of file management in web applications.

Changes Made

  • Blob Creation: Implemented the creation of a blob from the selected file and set it as the path in the PlatformFile object.

∑ Code Snippet

void addPickedFile(
  File file,
  Uint8List? bytes,
  String? path,
  Stream<List<int>>? readStream,
) {
  final blob = Blob([bytes ?? Uint8List(0)]);
  final blobUrl = Url.createObjectUrl(blob); // Create a blob URL

  pickedFiles.add(PlatformFile(
    name: file.name,
    path: blobUrl, // Set the blob URL as the path
    size: bytes != null ? bytes.length : file.size,
    bytes: bytes,
    readStream: readStream,
  ));

  if (pickedFiles.length >= files.length) {
    if (onFileLoading != null) {
      onFileLoading(FilePickerStatus.done);
    }
    filesCompleter.complete(pickedFiles);
  }
}

Benefits

Enhanced File Handling: Allows for seamless integration of file data as URLs, making it easier to work with files in web applications.
Checklist

  • I have tested the changes locally.

Related Issues

Additional Notes

Please review the changes and let me know if further modifications are needed. Thank you! 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant