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.

Http File Uploader #

License: MIT coverage

A en_file_uploader plugin to handle the file upload using http package.

http_file_uploader requires en_file_uploader package. More info about en_file_uploader here

Features #

  • use HttpFileHandler to handle a file upload;
  • use HttpChunkedFileHandler to handle a file upload in chunk;
  • use HttpRestorableChunkedFileHandler to handle a file upload in chunk with the capability to restore the upload.

Usage #

  1. Create a new instance of HttpFileHandler, HttpChunkedFileHandler or HttpRestorableChunkedFileHandler.
  2. Create a FileUploadController with the created handler
  3. Call controller.upload
import 'package:en_file_uploader/en_file_uploader.dart';
import 'package:http_file_uploader/http_file_uploader.dart';
import 'package:http/http.dart';

main() async {
  final client = Client();
  final file = XFile("fake_file");

  final baseRequestPath = "my-server";

  final restorableHandler = HttpRestorableChunkedFileHandler(
    client: client,
    file: file,
    presentMethod: "POST",
    chunkMethod: "PATCH",
    statusMethod: "HEAD",
    presentPath: "$baseRequestPath/upload/presentation",
    chunkPath: (presentation, _) =>
        "$baseRequestPath/upload/${presentation.id}/chunk",
    statusPath: (presentation) =>
        "$baseRequestPath/upload/${presentation.id}/status",
    presentHeaders: {
      "size": file.lengthSync().toString(),
    },
    chunkHeaders: (presentation, chunk) {
      return {
        "from": chunk.start.toString(),
        "end": chunk.end.toString(),
      };
    },
    statusHeaders: null,
    presentParser: (response) =>
        FileUploadPresentationResponse(id: jsonDecode(response.body)),
    statusParser: (response) =>
        FileUploadStatusResponse(nextChunkOffset: jsonDecode(response.body)),
    chunkSize: 1024 * 1024, // 1mb
    presentBody: null, chunkBody: null,
    statusBody: null,
  );

  final controller = FileUploadController(restorableHandler);
  await controller.upload();
}

8
likes
160
points
75
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