I got an error while trying to serve files over the http server from android download folder.
I dont know why it works fine on android emulator but not works the same appication in real android device : realme 6 runnig android 10
File storage Permissions granted :
- Emulator pixel 6 pro API 30 : Allow acces to media only
- Realme 6 android 10: Allow
Code i tried :
`Future localShelf() async {
// serving directory
const folderToServe = 'storage/emulated/0/Download/';
final address = InternetAddress.loopbackIPv4;
const port = 8989;
// creates a [ShelfVirtualDirectory] instance and provides a [Router] instance.
final folderPath = p.join(
Directory.current.path,
folderToServe,
);
final virDir = ShelfVirtualDirectory(folderPath);
final apiRouter = Router()
..mount('/routerstatic/', virDir.router)
..mount('/mountstatic/', virDir.handler)
..mount('/nodirlisting/',
ShelfVirtualDirectory(folderPath, listDirectory: true).handler)
// ..mount('/fsrootstatic/', ShelfVirtualDirectory('/').handler)
..get('/getstatic/', virDir.handler)
..get('/api/user', () => Response.ok('/api/user'))
..get('/api', () => Response.ok('/api'))
..mount('/', virDir.handler);
// using [Pipeline] from shelf we can add a logging middleware.
// we can use handler provided by [Router] instance.
final pipline =
const Pipeline().addMiddleware(logRequests()).addHandler(apiRouter);
// add the handler to [Cascade]
final server = await io.serve(
pipline,
address,
port,
);
print('Server is running at http://${server.address.host}:${server.port}');
}`