ashx图片上传接收
发送数据流方法 /// <summary>
/// PostBinaryData
/// </summary>
/// <param name="url">要发送的 url 网址</param>
/// <param name="bytes">要发送的数据流</param>
/// <returns></returns>
public string PostBinaryData(string url, byte[] bytes)
{
//下面是测试例子
//string url = "http://www.test.com/test.ashx";
//string img = HttpContext.Current.Server.MapPath("../images/test.jpg");
//byte[] bytes = File.ReadAllBytes(img);
HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(url);
wRequest.ContentType = "multipart/form-data";
wRequest.ContentLength = bytes.Length;
wRequest.Method = "POST";
Stream stream = wRequest.GetRequestStream();
stream.Write(bytes, 0, bytes.Length);
stream.Close();
HttpWebResponse wResponse = (HttpWebResponse)wRequest.GetResponse();
StreamReader sReader = new StreamReader(wResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string str = sReader.ReadToEnd();
sReader.Close();
wResponse.Close();
return str;
} public void GetBinaryData()
{
string imgFile = DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
string filePath = HttpContext.Current.Server.MapPath(imgFile);
//方法一
int lang = HttpContext.Current.Request.TotalBytes;
byte[] bytes = HttpContext.Current.Request.BinaryRead(lang);
string content = System.Text.Encoding.UTF8.GetString(bytes);
FileStream fStream = new FileStream(filePath, FileMode.Create, FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fStream);
bw.Write(bytes);
bw.Close();
fStream.Close();
//方法二
Bitmap img = new Bitmap(HttpContext.Current.Request.InputStream);
img.Save(filePath);
HttpContext.Current.Response.Write("ok");
}
接收数据流方法
ashx图片上传接收的更多相关文章
- ashx 图片上传路径URL
ashx 图片上传 为了方便多出调用图片上传方法 首先我们将图片上传方法抽离出来 创建ashx 一个新的方法 using System; using System.Collection ...
- ashx 图片上传
为了方便多出调用图片上传方法 首先我们将图片上传方法抽离出来 创建ashx 一个新的方法 using System; using System.Collections.Generic; u ...
- .NET 图片上传接收类
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- bootstrap-fileinput 图片上传
bootstrap-fileinput 源文件 在网上下载 CSS: <link href="../../static/Bootstrap/css/plugins/bootstrap- ...
- asp.net 百度编辑器 UEditor 上传图片 图片上传配置 编辑器配置 网络连接错误,请检查配置后重试
1.配置ueditor/editor_config.js文件,将 //图片上传配置区 ,imageUrl:URL+"net/imageUp.ashx" //图片上传提交地址 ,im ...
- CKEditor不借助CKFinder实现图片上传(.net版 ashx实现)
参考博客:http://blog.csdn.net/mydwr/article/details/8669594 本人版本:4.4.6 打开文件:ckeditor/plugins/image/dialo ...
- 微信小程序开发之多图片上传+服务端接收
前言: 业务需求,这次需要做一个小程序同时选中三张图片一起上传到服务端,后端使用的.NET WEBAPI接收数据保存. 使用技术: 在这章中将会使用到微信小程序wx.uploadFile(Object ...
- [转]微信小程序开发(二)图片上传+服务端接收
本文转自:http://blog.csdn.net/sk719887916/article/details/54312573 文/YXJ 地址:http://blog.csdn.net/sk71988 ...
- ajax图片上传(asp.net +jquery+ashx)
一.建立Default.aspx页面 <%@ Page Language="C#" AutoEventWireup="true" CodeFile=&q ...
随机推荐
- 转:【专题二】HTTP协议详解
我们在用Asp.net技术开发Web应用程序后,当用户在浏览器输入一个网址时就是再向服务器发送一个HTTP请求,此时就使用了应用层的HTTP协议,在上一个专题我们简单介绍了网络协议的知识,主要是为了后 ...
- 国外互联网大企业(flag)的涨薪方式
国外互联网大企业(flag)指的是:Facebook,Google,Amazon,LinkedIn 至于 A 代表哪家公司存在争议:有人说是Amazon,也有说是Apple,现在更有人说应该是AirB ...
- javanio2
package com.lanhuigu.nio.selector; import java.net.InetSocketAddress; import java.nio.ByteBuffer; im ...
- BUAA 111 圆有点挤
题目描述 gg最近想给女友送两个精美的小礼品:两个底面半径分别为R1和R2的圆柱形宝石,并想装在一个盒子里送给女友. 好不容易找到了一个长方体的盒子,其底面为A*B的矩形,他感觉好像宝石装不进去,但又 ...
- 清明 DAY 1
数学基础 Part 1. 高精度计算 Part 2. 模意义下的运算 mod 对一个数取模,其实就是取余数 注意: • 无除法运算 • ...
- node 读取多个文件、合并多个文件、读写多个文件
一.读取文件 1.找文件中匹配的内容 let fs = require('fs') let content = fs.readFileSync('/Users/**/desktop/Test.txt' ...
- Linux下的Jmeter运行测试
本文主要介绍Jmeter脚本如何在Linux通过no GUI的方式运行.总共分三部分: 1.Linux下JDK的安装及环境变量的配置 2.Linux下Jmeter的安装及环境变量的配置 3.运行结果的 ...
- javaweb笔记—02
1.compatible:adj. 兼容的:能共处的:可并立的2.web所有的请求都是http请求,http请求默认的编码是ISO-8859-1,不支持utf-8,要统一设置前台和后台一样,才不会乱码 ...
- 2019/3/25 wen 包,对象的行为
- BeanCreationException: Error creating bean with name 'transactionManager' defined
BeanCreationException: Error creating bean with name 'transactionManager' defined in \WEB-INF\classe ...