是否可以将字节[]转换为HttpPostedFile? [英] Is it possible to convert byte [] to HttpPostedFile?

查看:63
本文介绍了是否可以将字节[]转换为HttpPostedFile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将byte []转换为HttpPostedFile?

Is it possible to convert a byte[] to a HttpPostedFile?

System.Web.HttpPostedFile objFile = fileData;

其中fileData是图像的字节数组,给出无法隐式转换的错误".

where fileData is a byte array of an image, gives a "can not be implicitly converted error".

推荐答案

如果您查看源上课,您会看到一些东西.

If you look at the source for the class you'll see a few things.

  1. 构造函数是 internal ,因此您永远不会直接构造实例.
  2. 该类具有 minimum 个功能.
  3. 该类是 sealed ,所以您不能使用继承添加自己的构造函数.
  1. The constructor is internal, so you'll never directly construct an instance.
  2. The class has minimal functionality.
  3. The class is sealed, so you can't add your own constructor using inheritance.

您无需尝试将字节数组转换为 HttpPostedFile 的实例,而是将下游方法转换为接受 byte [] 作为输入或 Stream .如果需要 HttpPostedFile 的其他属性,则可以直接将它们作为附加参数发送,或编写自己的类来包装它们.

Instead of trying to convert a byte array into an instance of HttpPostedFile, you'll have a much smoother experience by converting your downstream methods to accept byte[] as input, or maybe Stream. If you need the other properties of HttpPostedFile, then you could just send them in directly as additional parameters, or write your own class to wrap them up.

这篇关于是否可以将字节[]转换为HttpPostedFile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆