http_file_uploader 2.1.3 copy "http_file_uploader: ^2.1.3" to clipboard
http_file_uploader: ^2.1.3 copied to clipboard

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

example/lib/example.dart

import 'dart:convert';

import 'package:en_file_uploader/en_file_uploader.dart';
import 'package:file_uploader_utils/file_uploader_utils.dart' as utils;
import 'package:http/http.dart';
import 'package:http_file_uploader/http_file_uploader.dart';

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

  const baseRequestPath = 'my-request';

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

  final restorableHandler = HttpRestorableChunkedFileHandler(
    client: client,
    file: XFile(file.path),
    chunkMethod: 'PATCH',
    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;
    },
    presentParser: (response) =>
        FileUploadPresentationResponse(id: response.body),
    statusParser: (response) => FileUploadStatusResponse(
      nextChunkOffset: jsonDecode(response.body) as int,
    ),
    chunkSize: 1024 * 1024, // 1mb
  );

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

  // print("done!");
}
8
likes
160
points
76
downloads

Publisher

verified publishermattiapispisa.it

Weekly Downloads

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

Homepage
Repository (GitHub)
View/report issues

Topics

#http #file #upload #chunks #retry

Documentation

API reference

License

MIT (license)

Dependencies

en_file_uploader, file_uploader_socket_interfaces, http

More

Packages that depend on http_file_uploader