internet_file 1.2.0 copy "internet_file: ^1.2.0" to clipboard
internet_file: ^1.2.0 copied to clipboard

A internet file getter (also optional downloader) that works in all platforms

Logo

A internet file getter (also optional downloader) that works in all platforms (browsers, mobile, desktop, and server-side)


Pub

PurposeGetting StartedApiCredits

Purpose #

The library is made to allow direct access to Internet files on all platforms. It also has the middleware to store files locally if needed. Aimed primarily at use with plugins, without the ability to work with the Internet

Getting Started #

Simple usage anywhere:

import 'package:internet_file/internet_file.dart';

final Uint8List bytes = await InternetFile.get(
    'https://github.com/rbcprolabs/icon_font_generator/raw/master/example/lib/icon_font/ui_icons.ttf',
    progress: (receivedLength, contentLength) {
      final percentage = receivedLength / contentLength * 100;
      print(
          'download progress: $receivedLength of $contentLength ($percentage%)');
    },
);

For local store files you can usage InternetFileStorageIO (not works on web):

import 'package:internet_file/storage_io.dart';

final storageIO = InternetFileStorageIO();

await InternetFile.get(
    'https://github.com/rbcprolabs/icon_font_generator/raw/master/example/lib/icon_font/ui_icons.ttf',
    storage: storageIO,
    storageAdditional: storageIO.additional( 
      filename: 'ui_icons.ttf',
      location: '',
    ),
);

Or you can write you own storage not requires io (web support etc.):

class MyOwnInternetFileStorage extends InternetFileStorage {
  @override
  Future<Uint8List?> findExist(
    String url,
    InternetFileStorageAdditional additional,
  ) {
    # find local here

    # access you own string property:
    print(additional['my_string_property'] as String);

    # access you own any type property:
    print((additional['my_date_property'] as DateTime).toString())
  }

  @override
  Future<void> save(
    String url,
    InternetFileStorageAdditional additional,
    Uint8List bytes,
  ) async {
    # save file here
  }
}

final myOwnStorage = MyOwnInternetFileStorage();
await InternetFile.get(
    'https://github.com/rbcprolabs/icon_font_generator/raw/master/example/lib/icon_font/ui_icons.ttf',
    storage: myOwnStorage,
    storageAdditional: {
        'my_string_property': 'string',
        'my_int_property': 99,
        'my_date_property': DateTime.now(),
    },
);

Api #

InternetFile.get params

Parameter Description Optional Default
url Link to network file required -
headers Headers passed for wile load optional -
progress Callback with received & all bytes length progress value called when file loads optional -
storage Implements of InternetFileStorage with save & find local methods for saving files optional -
storageAdditional Additional args for pass to InternetFileStorage implementation passed in storage optional {}

Full api reference available here

Credits #

Inspired by flutter_cache_manager, but make for support all platforms

Uses:

  • http - for file loading from internet
  • path - for filename & location joint in InternetFileStorageIO
  • universal_file - for work File in web

Created for usage in:

115
likes
140
points
49k
downloads

Publisher

verified publisherserge.software

Weekly Downloads

A internet file getter (also optional downloader) that works in all platforms

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

http, path, universal_file

More

Packages that depend on internet_file