dio_file_uploader 0.2.0 copy "dio_file_uploader: ^0.2.0" to clipboard
dio_file_uploader: ^0.2.0 copied to clipboard

A en_file_uploader plugin to handle the file upload using dio package. Provides the capability to upload a file in chunks with built-in retry handling.

example/lib/example.dart

// ignore_for_file: avoid_redundant_argument_values, avoid_print example

import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:dio_file_uploader/dio_file_uploader.dart';
import 'package:en_file_uploader/en_file_uploader.dart';
import 'package:file_uploader_utils/file_uploader_utils.dart' as utils;

void main() async {
  final client = Dio();
  final file = utils.createIoFile();

  const baseRequestPath = 'my-request';

  final headers = {'Authorization': 'Bearer XXX'};

  final restorableHandler = DioRestorableChunkedFileHandler(
    client: client,
    file: XFile(file.path),
    presentMethod: 'POST',
    chunkMethod: 'PATCH',
    statusMethod: 'HEAD',
    presentPath: baseRequestPath,
    chunkPath: (presentation, _) => '$baseRequestPath&patch=${presentation.id}',
    statusPath: (presentation) => '$baseRequestPath&status=${presentation.id}',
    presentHeaders: {
      'Upload-Length': file.lengthSync().toString(),
      ...headers,
    },
    chunkHeaders: (presentation, chunk) {
      return headers;
    },
    statusHeaders: null,
    presentParser: (response) => FileUploadPresentationResponse(
      id: response.data as String,
    ),
    statusParser: (response) => FileUploadStatusResponse(
      nextChunkOffset: jsonDecode(response.data as String) as int,
    ),
    chunkSize: 1024 * 1024, // 1mb
    presentBody: null,
    chunkBody: null,
    statusBody: null,
  );

  final controller = FileUploadController(
    restorableHandler,
    logger: utils.fileUploaderLogger,
  );
  await controller.upload();

  print('done!');
}
5
likes
160
points
150
downloads

Documentation

API reference

Publisher

verified publishermattiapispisa.it

Weekly Downloads

A en_file_uploader plugin to handle the file upload using dio package. Provides the capability to upload a file in chunks with built-in retry handling.

Homepage
Repository (GitHub)
View/report issues

Topics

#dio #file #upload #chunks #retry

License

MIT (license)

Dependencies

dio, en_file_uploader, file_uploader_socket_interfaces

More

Packages that depend on dio_file_uploader