简体   繁体   中英

extend web server to serve static files

I want to extend a web server which is only able to handle RPC handling now. The web server is written in C#. It provides a abstract handler function like following:

public string owsHandler(string request, string path, string param,
                                      OSHttpRequest httpRequest, OSHttpResponse httpResponse)

And I wrote following code to handle image files:

Bitmap queryImg = new Bitmap(path);
System.IO.MemoryStream stream = new System.IO.MemoryStream();
queryImg.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
queryImg.Dispose();
byte[] byteImage = stream.ToArray();
stream.Dispose();
return Convert.ToBase64String(byteImage);

And I test it in the browser, the image is returned but the image dimension info is missed. Shall I add something more to the code? Or is any general way to server static files? I do not want to serve it in a ASP.net server.

Thanks

不要尝试将文件加载到内存中的位图图像中,只需按原样提供即可。

return Convert.ToBase64String(File.ReadAllBytes(path));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM