dio_file_uploader

Creator: coderz1093

Last updated:

0 purchases

dio_file_uploader Image
dio_file_uploader Images

Languages

Categories

Add to Cart

Description:

dio file uploader

Dio File Uploader #
A en_file_uploader plugin to handle the file upload using dio package.
dio_file_uploader requires en_file_uploader package.
More info about en_file_uploader here
Features #

use DioFileHandler to handle a file upload;
use DioChunkedFileHandler to handle a file upload in chunk;
use DioRestorableChunkedFileHandler to handle a file upload in chunk with the capability to restore the upload.

Usage #

Create a new instance of DioFileHandler, DioChunkedFileHandler or DioRestorableChunkedFileHandler.
Create a FileUploadController with the created handler
Call controller.upload

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;

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

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

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

print("done!");
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.