http_file_uploader 2.1.0 copy "http_file_uploader: ^2.1.0" to clipboard
http_file_uploader: ^2.1.0 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:http_file_uploader/http_file_uploader.dart';
import 'package:http/http.dart';
import 'package:file_uploader_utils/file_uploader_utils.dart' as utils;

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

  final baseRequestPath = "my-request";

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

  final restorableHandler = HttpRestorableChunkedFileHandler(
    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.body),
    statusParser: (response) =>
        FileUploadStatusResponse(nextChunkOffset: jsonDecode(response.body)),
    chunkSize: 1024 * 1024, // 1mb
    presentBody: null,
    chunkBody: null,
    statusBody: null,
  );

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

  print("done!");
}
8
likes
0
points
60
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

License

unknown (license)

Dependencies

en_file_uploader, file_uploader_socket_interfaces, http

More

Packages that depend on http_file_uploader