Coder Social home page Coder Social logo

Comments (5)

navaronbracke avatar navaronbracke commented on June 12, 2024 2

See the fix in #1496

from flutter_file_picker.

MODE83-PROJET-DEV avatar MODE83-PROJET-DEV commented on June 12, 2024

I have exactly the same problem on the web part.

I'm trying to find a solution on my side.

from flutter_file_picker.

MODE83-PROJET-DEV avatar MODE83-PROJET-DEV commented on June 12, 2024

Okay I'm back with a solution

Already down to version 6.2.1 because apparently there is a typing error in the file stream
All execution must be in the same method, processing the file and sending the file, the web part of flutter is really very capricious, separated it is two methods would only lose the integrity of the result file by a phenomenon which surpasses me
I had to build a class interface to separate the web part and the app part since the web part is allergic to dart.io

Exemple my code for web :

`
import "package:http/http.dart" as http;
Future setFile(FilePickerResult? result, String typeUpload, String fileUrl) async {
try {

  // if file
  if (result != null && result.files.isNotEmpty && result.files.single.readStream != null) {
    
   // Uri address
    Uri uri = Uri.parse(_urlList.urlPostUploadFile);

    /// array post 
    Map<String, String> requestMap = {
      "cible": typeUpload,
    };

    /// prepare to request file
    /// read stream ??? WTF type File ???? baaa it works with this ;)
    http.ByteStream stream = http.ByteStream(result.files.single.readStream!.asBroadcastStream());

    /// Include multiparte file
    var request = http.MultipartRequest('POST', uri);
    request.fields.addAll(requestMap);
    request.files.add(http.MultipartFile(
      'file',
      stream,
      result.files.first.size,
      filename: result.files.first.name,
    ));

    /// Post file
    var response = await request.send();
    if (response.statusCode == 200) {
      /// Lecture des données - retour serveur
      String responseString = await response.stream.bytesToString();

      print("REPONSE : $responseString");

      /// Décodage des données json
      var jsonData = jsonDecode(responseString);
      _setInfo = CtrlUploadData.fromJson(jsonData);

      /// check code info
      if (_setInfo.returnCode != 0 && _setInfo.returnCode <= 8) {
        return false;
      } else {
        return true;
      }
    } else {
      return false;
    }
  } else {
    return false;
  }
} catch (ex) {
  return false;
}

`

We really need to make an effort to clarify and enter into a standardized convention, the backtracking in this part of the code has been numerous on my side and the doc is not at all in line with what is happening concretely.

I spent some time on this and made the effort to detail everything, I hope this will be taken into account in the next patch

Sorry but it's frustrating for me to see this error several times

in particular it is the typing problem of result.files.first.readStream which poses recurring problems.
More info on this and clear documentation would not be refused.

Sorry for my English, best regards

from flutter_file_picker.

MODE83-PROJET-DEV avatar MODE83-PROJET-DEV commented on June 12, 2024

I would at least like to have a response from you before you close this thread ?!
Best regards

from flutter_file_picker.

MODE83-PROJET-DEV avatar MODE83-PROJET-DEV commented on June 12, 2024

Thanks

from flutter_file_picker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.