Home > Mobile >  Displaying multiple Items in the list to an ftp server Flutter
Displaying multiple Items in the list to an ftp server Flutter

Time:10-05

I want to display multiple Items in the list and store it in the ftp server. So far I can only store the first index, now I want when the user decides to take multiple photos, they can be stored also on the ftp server. So may you please help how can I loop through photos file list and achieve this: Check my code below

 final photos = <File>[];

 Future<void> fileUpload() async {
    FTPConnect ftpConnect = FTPConnect('xxxxxxxx',
        user: 'xxxxxxxxx',
        pass: 'xxxxxxxxx',
        port: xx,
        //isSecured: false,
        debug: true);
    try {
      File fileToUpload =  await File(photos.first.path);
      await ftpConnect.connect();
      await ftpConnect.changeDirectory('public_html');
      await ftpConnect.changeDirectory('assets');
      await ftpConnect.changeDirectory('images');
      await ftpConnect.changeDirectory('app');
      await ftpConnect.sizeFile('$photos');
      await ftpConnect.rename('CAP4077791735949912884.jpg', 'laptop.jpg');
      await ftpConnect.uploadFile(fileToUpload);
      await ftpConnect.disconnect();
    } catch (e) {
      //error
      await _log('Error: ${e.toString()}');
    }
  }

CodePudding user response:

Try putting the code in the loop with the length of the list of photos.

final photos = <File>[];
for (File photo in photos) {
  // your code to upload file to the FTP server
}

CodePudding user response:

A loop will do:

   photos.forEach((element) async {
      File _file = File(element.path);
      await ftpConnect.uploadFile(_file);
    });
  • Related