Untitled
unknown
java
a year ago
856 B
11
Indexable
public class MyHttpServer extends NanoHTTPD {
public MyHttpServer() throws IOException {
super(2222);
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
System.out.println("Server started on port 2222");
}
@Override
public Response serve(IHTTPSession session) {
try {
// 从 SMB 获取文件流
SmbFile smbFile = new SmbFile("smb://xybbz/docker/mp3.mp3", smbAuth);
InputStream inputStream = smbFile.getInputStream();
// 将文件通过 HTTP 发送
return newChunkedResponse(Response.Status.OK, "audio/mpeg", inputStream);
} catch (Exception e) {
e.printStackTrace();
return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, "text/plain", "Error reading file");
}
}
}
Editor is loading...
Leave a Comment