AndroidAsync icon indicating copy to clipboard operation
AndroidAsync copied to clipboard

SendFile Failed

Open chaocharleswang opened this issue 7 years ago • 2 comments

Hi, I tried the following code in the main activity:

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

    final File videoFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Download/mv.mp4");

    AsyncHttpServer server = new AsyncHttpServer();

    List<WebSocket> _sockets = new ArrayList<WebSocket>();

    server.get("/", new HttpServerRequestCallback() {
        @Override
        public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response)
        {
            long fileSize = videoFile.length();

            System.out.println("File Size: " + fileSize);

            response.sendFile(videoFile);
        }
    });

    server.listen(5000);
}

When I input http://10.0.0.234:5000/, I only get "File Size in Server: 63018711".

However, the browser shows "This 10.0.0.234 page can’t be found No webpage was found for the web address: http://10.0.0.234:5000/ Search Google for 234 5000 HTTP ERROR 404"

Can you help me with that? Thanks a lot!

chaocharleswang avatar May 01 '17 12:05 chaocharleswang

we have same question

VVZ1991 avatar Apr 10 '18 11:04 VVZ1991

I add ActivityCompat.requestPermissions(Main2Activity.this, PERMISSIONS_STORAGE, 1); to solved

zccguagua avatar Jun 23 '20 04:06 zccguagua