Giter Club home page Giter Club logo

Comments (4)

sagreine avatar sagreine commented on July 24, 2024

@jamesdixon , did you resolve this? My use case that led me here is pretty different, but I ended up doing something along the lines of:

  1. create virtual directory
  2. bind HTTP server to a local address, and on listen serve a file (in my case, a video that the user recorded)
  3. send that HTTP request somewhere, e.g. a browser or webview, which is then served the video file.

something like this, though this is typed from memory and bare minimum to get something up, very messy etc...

Future<String> _server(String _targetFile) async {
  VirtualDirectory staticFiles = VirtualDirectory('.')
    ..followLinks = true
    ..allowDirectoryListing = true
    ..jailRoot = false;
  var serverRequests =
      // this works if you only want to use your mobile phone to access via browser (navigate to localhost:4040 in a browser on your phone or in the app's flutter webview), but
      // i wanted to be able to access from another pc on network and that didn't work
      //await HttpServer.bind(InternetAddress.loopbackIPv4, 4040);
      await HttpServer.bind('0.0.0.0', 4040);
serverRequests.listen((event) async {
File targetFile = File(_targetFile);
// i think as-coded awaiting here is critical, but obviously you wouldn't do it this way.
assert(await targetFile.exists());
staticFiles.serveFile(targetFile, event);
});
//later, in a function call...
final pickedFile = await picker.getVideo(source: ImageSource.camera);
await _server(pickedFile.path);

from there, i could navigate to the phones IP address : /4040 e.g. http://10.0.0.76:4040/ in the browser on a pc and it would serve me the video file that the user just recorded. I didn't personally have a need to go further than that, and haven't messed with non-asset webviews myself.

there is this snippet if you need access to the server programmatically, though you can just use localhost:4040 or whatever port if you're using the phone to access it.
String local ="http://" + (await GetIp.ipAddress) + ":" + serverRequests.port.toString();

No idea if any of that's helpful or not but figured I'd share.

from local_assets_server.

hemmrich avatar hemmrich commented on July 24, 2024

I'd also love an update on this. I'm trying to download assets (incl HTML files) dynamically and display them in a webview. However, I'm unable to get local_assets_server to use getapplicationDocumentsDirectory() as an assetsBasePath.

from local_assets_server.

lesnitsky avatar lesnitsky commented on July 24, 2024

from local_assets_server.

lesnitsky avatar lesnitsky commented on July 24, 2024

implemented in v1.0.3

from local_assets_server.

Related Issues (12)

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.