Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

Upload multiple images in flutter by multipart

Future uploadmultipleimage(List images) async {
  var uri = Uri.parse("");
  http.MultipartRequest request = new http.MultipartRequest('POST', uri);
  request.headers[''] = '';
  request.fields['user_id'] = '10';
  request.fields['post_details'] = 'dfsfdsfsd';
  //multipartFile = new http.MultipartFile("imagefile", stream, length, filename: basename(imageFile.path));
  List<MultipartFile> newList = new List<MultipartFile>();
  for (int i = 0; i < images.length; i++) {
    File imageFile = File(images[i].toString());
    var stream =
        new http.ByteStream(DelegatingStream.typed(imageFile.openRead()));
    var length = await imageFile.length();
    var multipartFile = new http.MultipartFile("imagefile", stream, length,
        filename: basename(imageFile.path));
    newList.add(multipartFile);
  }
  request.files.addAll(newList);
  var response = await request.send();
  if (response.statusCode == 200) {
    print("Image Uploaded");
  } else {
    print("Upload Failed");
  }
  response.stream.transform(utf8.decoder).listen((value) {
    print(value);
  });
}
Comment

flutter ui upload multiple image

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:multi_image_picker/multi_image_picker.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<Asset> images = List<Asset>();
  String _error;

  @override
  void initState() {
    super.initState();
  }

  Widget buildGridView() {
    if (images != null)
      return GridView.count(
        crossAxisCount: 3,
        children: List.generate(images.length, (index) {
          Asset asset = images[index];
          return AssetThumb(
            asset: asset,
            width: 300,
            height: 300,
          );
        }),
      );
    else
      return Container(color: Colors.white);
  }

  Future<void> loadAssets() async {
    setState(() {
      images = List<Asset>();
    });

    List<Asset> resultList;
    String error;

    try {
      resultList = await MultiImagePicker.pickImages(
        maxImages: 300,
      );
    } on Exception catch (e) {
      error = e.toString();
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      images = resultList;
      if (error == null) _error = 'No Error Dectected';
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: <Widget>[
            Center(child: Text('Error: $_error')),
            RaisedButton(
              child: Text("Pick images"),
              onPressed: loadAssets,
            ),
            Expanded(
              child: buildGridView(),
            )
          ],
        ),
      ),
    );
  }
}
Comment

how to upload multiple image to server flutter 2021

sdsdsdsd
Comment

PREVIOUS NEXT
Code Example
Shell :: linux distributions command line 
Shell :: curl with regex 
Shell :: htop ubuntu installation command 
Shell :: ppm to ppb 
Shell :: how to move a file in bash 
Shell :: mac terminal screenshot 
Shell :: how to remove package files in linux 
Shell :: where are chocolatey packages installed 
Shell :: get program path powershell 
Shell :: npm install firebase @angular/fire 
Shell :: windows run shell script 
Shell :: install pydotplus - tox by pip ubuntu 
Shell :: git percentage of authorship 
Shell :: bash split pipe output by delimiter 
Shell :: WSL2 git init 
Shell ::  
Shell :: codeception environnement variable not found 
Shell :: p10k show on command 
Shell :: count symlink dir bash 
Shell :: @ module not install webstorm vue 
Shell :: Warning: Broken symlinks were found. Remove them with `brew cleanup`: 
Shell :: power shell scribt to copy files 
Shell :: Show CSF version 
Shell :: fetch only one branch 
Shell :: powershell invoke 
Shell :: bash multiplication of arguments 
Shell :: install webdav ubuntu 18.04 
Shell :: add-windowscapability rsat 
Shell :: opposite of diff unix 
Shell :: atmel studio download ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =