salim-lachdhaf / dartFTP

dartFTP
MIT License
9 stars 17 forks source link

Exception: Invalid Image Data #21

Closed mrboggyman16 closed 7 months ago

mrboggyman16 commented 1 year ago

I am downloading image from ftp and saving it into a file but when I ma trying to show it son screen I got this exception

Can anyone help ?

final ftpConnect = FTPConnect(DBConstants.ftpServer,
        user: DBConstants.ftpUser, pass: DBConstants.ftpPassword);

    await ftpConnect.connect();
    await ftpConnect.changeDirectory(DBConstants.publicImgDirPath);

    final appDir = await getApplicationDocumentsDirectory();
    final imgName = studentFilePath.split('images/').last;
    final localFilePath = '${appDir.path}/$imgName';
    final fFile = File(localFilePath);

    try {
      final downloadedFile = await ftpConnect.downloadFile(imgName, fFile);

      LoadingHelper.dismissLoader();
      return fFile;
    } on FTPConnectException catch (e) {
      LoadingHelper.dismissLoader();
      LoadingHelper.showErrorDialog(e.message);
    } finally {
      ftpConnect.disconnect();
    }
    LoadingHelper.dismissLoader();
mhanzla80 commented 1 year ago

Facing the same error.

mhanzla80 commented 1 year ago

Image got corrupt while downloading and throwing this error

E/FlutterJNI( 4321): Failed to decode image E/FlutterJNI( 4321): android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'unimplemented'Input contained an error. Flutterr image error

TakaTeke commented 1 year ago

Hello. I also ran into the same issue with file uploads and downloads. So I looked into the source code of "ftpconnect". In 'ftp_socket.dart', 'TransferType.auto' is the default, sending commands with 'TYPE A'. Normally, we should use 'TYPE A' for text-based files and 'Type I' for byte mode (binary mode) files such as image files, depending on the type of file we want to send and receive. So when uploading files, for byte mode files, I inserted "await ftpConnect.sendCustomCommand('TYPE I');" before "await ftpConnect.uploadFile(fileToUpload);". The result was a success. Also when downloading files, for byte mode files, I inserted "await ftpConnect.sendCustomCommand('TYPE I');" before "await ftpConnect.downloadFile(fileName, File('myFileFromFTP.txt'));". The results were equally successful. Try it yourself as well.

salim-lachdhaf commented 7 months ago

thnx to @TakaTeke, just try as he said or:

ftpConnect.setTransferType(TransferType.binary);

And don't forget to go back to

ftpConnect.setTransferType(TransferType.auto);