0

On the server side I am using following code answered by a member. I want to send the name of the file and display it on client side.

public class StackOverflowMp3Server extends NanoHTTPD {

    public StackOverflowMp3Server() {
        super(8089);
    }

    @Override
    public Response serve(String uri, Method method,
        Map<String, String> header, Map<String, String> parameters,
        Map<String, String> files) {
        String answer = "";

        FileInputStream fis = null;
        try {
            fis = new FileInputStream(Environment.getExternalStorageDirectory()
                + "/music/musicfile.mp3");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return new NanoHTTPD.Response(Status.OK, "audio/mpeg", fis);
        //adding headers here
    }
}
mach
  • 8,315
  • 3
  • 33
  • 51
SSM
  • 1

1 Answers1

0

You should write another service to return file name

public class FileNameServer extends NanoHTTPD {

public FileNameServer () {
    super(8089);
}

@Override
public Response serve(String uri, Method method,
    Map<String, String> header, Map<String, String> parameters,
    Map<String, String> files) {
    String answer = "";

    String fileName = "";
    try {
        fileName = Environment.getExternalStorageDirectory()
            + "/music/musicfile.mp3";
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return new NanoHTTPD.Response(Status.OK, "string", fileName);
    //adding headers here
}
Hojjat
  • 815
  • 1
  • 10
  • 25