适用场景:实战开发时,有时候前端上传的文件并不是存放在网站所在的服务器,需要通过后台处理后转发至指定服务器进行存储。具体源码如下。
部分源码:
public void ProcessRequest(HttpContext context)
{
string result = "";//返回数据
SystemHelper helper = new SystemHelper();
//调用上传接口
string InterfaceAddr = helper.ReadSetting("APIAdress" );//存储服务器的接口地址
try
{
if (context.Request.Files.Count > 0)
{
var curRequest = context.Request;
byte[] inputBytes;
int streamLength;
using (var stream = curRequest.InputStream)
{
streamLength = stream.Length.ToInt32();
inputBytes = new byte[streamLength + 1];
stream.Read(inputBytes, 0, streamLength);
stream.Close();
}
//构造请求

本文介绍了在实际开发中,如何使用C#后端接收前端上传的文件,并将这些文件转发到其他服务器进行存储的场景。提供的源码示例适用于图片和文件的上传处理。
1890

被折叠的 条评论
为什么被折叠?



