Comments (4)
@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:
- create virtual directory
- bind HTTP server to a local address, and on listen serve a file (in my case, a video that the user recorded)
- 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.
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.
from local_assets_server.
implemented in v1.0.3
from local_assets_server.
Related Issues (12)
- Security HOT 1
- play vedio in ios
- host flutter web locally from mobile HOT 3
- Serve assets from fs directory example HOT 1
- example not working under windows
- Remove `print` from the code and add a log instead
- Unable to preventDefault inside passive event listener due to target being treated as passive HOT 1
- Web Page not available HOT 1
- Logging? HOT 3
- local_assets_server.dart is legacy HOT 1
- Does not work on Windows (404 error) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from local_assets_server.