本文整理汇总了C#中HttpFile类的典型用法代码示例。如果您正苦于以下问题:C# HttpFile类的具体用法?C# HttpFile怎么用?C# HttpFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpFile类属于命名空间,在下文中一共展示了HttpFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: checkUploadPic
/// <summary>
/// 检查上传的图片是否合法
/// </summary>
/// <param name="postedFile"></param>
/// <param name="errors"></param>
public static void checkUploadPic( HttpFile postedFile, Result errors )
{
if (postedFile == null) {
errors.Add( lang.get( "exPlsUpload" ) );
return;
}
// 检查文件大小
if (postedFile.ContentLength <= 1) {
errors.Add( lang.get( "exPlsUpload" ) );
return;
}
int uploadMax = 1024 * 1024 * config.Instance.Site.UploadPicMaxMB;
if (postedFile.ContentLength > uploadMax) {
errors.Add( lang.get( "exUploadMax" ) + " " + config.Instance.Site.UploadPicMaxMB + " MB" );
return;
}
// TODO: (flash upload) application/octet-stream
//if (postedFile.ContentType.ToLower().IndexOf( "image" ) < 0) {
// errors.Add( lang.get( "exPhotoFormatTip" ) );
// return;
//}
// 检查文件格式
if (Uploader.isAllowedPic( postedFile ) == false) {
errors.Add( lang.get( "exUploadType" ) + ":" + postedFile.FileName + "(" + postedFile.ContentType + ")" );
}
}
开发者ID:robin88,项目名称:wojilu,代码行数:35,代码来源:Uploader.cs
示例2: CometWorker_FileUploadRequested
static void CometWorker_FileUploadRequested(ref HttpFile file)
{
string fileName = file.ServerMapPath + "\\Upload\\" + file.FileName;
file.SaveAs(fileName);
string resourceName = file.FileName.Replace("&", "_");
ResourceManager.AddReplaceResource(fileName, resourceName, ResourceType.Image, file.ClientId);
CometWorker.SendToClient(file.ClientId, JSON.Method("ShowImage", resourceName));
}
开发者ID:wangchunlei,项目名称:MyGit,代码行数:8,代码来源:Default.aspx.cs
示例3: TestDisposedFilename
public void TestDisposedFilename()
{
HttpFile file = new HttpFile("object", "object", "object");
file.Dispose();
#pragma warning disable 168
Assert.Throws(typeof (ObjectDisposedException), delegate { string tmp = file.Filename; });
#pragma warning restore 168
}
开发者ID:kow,项目名称:Aurora-Sim,代码行数:9,代码来源:HttpFileTest.cs
示例4: TestFileDeletion
/// <summary> Test to make sure files gets deleted upon disposing </summary>
public void TestFileDeletion()
{
string path = Environment.CurrentDirectory + "\\tmptest";
HttpFile file = new HttpFile("testFile", path, "nun");
File.WriteAllText(path, "test");
file.Dispose();
Assert.Equal(File.Exists(path), false);
}
开发者ID:kow,项目名称:Aurora-Sim,代码行数:11,代码来源:HttpFileTest.cs
示例5: TestModifications
public void TestModifications()
{
HttpFile file = new HttpFile("testFile", "nun", "nun");
_form.AddFile(file);
Assert.Equal(file, _form.GetFile("testFile"));
_form.Add("valueName", "value");
Assert.Equal("value", _form["valueName"].Value);
_form.Clear();
Assert.Null(_form.GetFile("testFile"));
Assert.Null(_form["valueName"].Value);
}
开发者ID:kow,项目名称:Aurora-Sim,代码行数:13,代码来源:HttpFormTest.cs
示例6: savePostData
private AttachmentTemp savePostData( HttpFile postedFile, Result result ) {
// 将附件存入数据库
AttachmentTemp uploadFile = new AttachmentTemp();
uploadFile.FileSize = postedFile.ContentLength;
uploadFile.Type = postedFile.ContentType;
uploadFile.Name = result.Info.ToString();
uploadFile.Description = ctx.Post( "FileDescription" );
uploadFile.ReadPermission = ctx.PostInt( "FileReadPermission" );
uploadFile.Price = ctx.PostInt( "FilePrice" );
uploadFile.AppId = ctx.app.Id;
attachService.CreateTemp( uploadFile, (User)ctx.viewer.obj, ctx.owner.obj );
return uploadFile;
}
开发者ID:2014AmethystCat,项目名称:wojilu,代码行数:14,代码来源:UploaderController.cs
示例7: IsAllowedPic
/// <summary>
/// 是否允许的格式
/// </summary>
/// <param name="pfile"></param>
/// <returns></returns>
public static Boolean IsAllowedPic( HttpFile pfile )
{
String[] types = { "jpg", "gif", "bmp", "png", "jpeg" };
String[] cfgTypes = config.Instance.Site.UploadPicTypes;
if (cfgTypes != null && cfgTypes.Length > 0) types = cfgTypes;
if (containsChar( cfgTypes, "*" )) return true;
foreach (String ext in types) {
if (strUtil.IsNullOrEmpty( ext )) continue;
String extWithDot = ext.StartsWith( "." ) ? ext : "." + ext;
if (strUtil.EqualsIgnoreCase( Path.GetExtension( pfile.FileName ), extWithDot )) return true;
}
return false;
}
开发者ID:2014AmethystCat,项目名称:wojilu,代码行数:21,代码来源:Uploader.cs
示例8: CheckUploadPic
/// <summary>
/// 检查上传的图片是否合法
/// </summary>
/// <param name="postedFile"></param>
/// <param name="errors"></param>
public static void CheckUploadPic( HttpFile postedFile, Result errors )
{
if (postedFile == null) {
errors.Add( lang.get( "exPlsUpload" ) );
return;
}
// 检查文件大小
if (postedFile.ContentLength <= 1) {
errors.Add( lang.get( "exPlsUpload" ) );
return;
}
int uploadMax = 1024 * 1024 * config.Instance.Site.UploadPicMaxMB;
if (postedFile.ContentLength > uploadMax) {
errors.Add( lang.get( "exUploadMax" ) + " " + config.Instance.Site.UploadPicMaxMB + " MB" );
return;
}
// 检查文件格式
if (Uploader.IsAllowedPic( postedFile ) == false) {
errors.Add( lang.get( "exUploadType" ) + ":" + postedFile.FileName + "(" + postedFile.ContentType + ")" );
}
}
开发者ID:2014AmethystCat,项目名称:wojilu,代码行数:29,代码来源:Uploader.cs
示例9: SaveImg
/// <summary>
/// 保存上传的图片
/// </summary>
/// <param name="postedFile"></param>
/// <param name="arrThumbType"></param>
/// <returns></returns>
public static Result SaveImg( HttpFile postedFile, ThumbnailType[] arrThumbType )
{
Result result = new Result();
checkUploadPic( postedFile, result );
if (result.HasErrors) {
logger.Info( result.ErrorsText );
return result;
}
String pathName = PathHelper.Map( sys.Path.DiskPhoto );
String photoName = Img.GetPhotoName( pathName, postedFile.ContentType );
String filename = Path.Combine( pathName, photoName );
try {
postedFile.SaveAs( filename );
foreach (ThumbnailType ttype in arrThumbType) {
saveThumbSmall( filename, ttype );
}
}
catch (Exception exception) {
logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message );
result.Add( lang.get( "exPhotoUploadErrorTip" ) );
return result;
}
result.Info = photoName.Replace( @"\", "/" );
return result;
}
开发者ID:robin88,项目名称:wojilu,代码行数:36,代码来源:Uploader.cs
示例10: SaveGroupLogo
/// <summary>
/// 保存群组 logo
/// </summary>
/// <param name="postedFile"></param>
/// <param name="groupUrlName"></param>
/// <returns></returns>
public static Result SaveGroupLogo( HttpFile postedFile, String groupUrlName )
{
return SaveImg( sys.Path.DiskGroupLogo, postedFile, groupUrlName, config.Instance.Group.LogoWidth, config.Instance.Group.LogoHeight );
}
开发者ID:robin88,项目名称:wojilu,代码行数:10,代码来源:Uploader.cs
示例11: upload_private
private static Result upload_private( String uploadPath, HttpFile postedFile, String picName )
{
logger.Info( "uploadPath:" + uploadPath + ", picName:" + picName );
Result result = new Result();
Uploader.checkUploadPic( postedFile, result );
if (result.HasErrors) return result;
String str = PathHelper.Map( uploadPath );
String str2 = picName + "." + Img.GetImageExt( postedFile.ContentType );
String srcPath = Path.Combine( str, str2 );
try {
postedFile.SaveAs( srcPath );
saveAvatarThumb( srcPath );
}
catch (Exception exception) {
logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message );
result.Add( lang.get( "exPhotoUploadErrorTip" ) );
return result;
}
// 返回的信息是缩略图
String thumbPath = Img.GetThumbPath( srcPath );
result.Info = "face/" + Path.GetFileName( thumbPath );
return result;
}
开发者ID:robin88,项目名称:wojilu,代码行数:27,代码来源:AvatarUploader.cs
示例12: SaveFileOrImage
/// <summary>
/// 保存上传的文件,如果是图片,则处理缩略图
/// </summary>
/// <param name="postedFile"></param>
/// <returns></returns>
public static Result SaveFileOrImage( HttpFile postedFile )
{
if (postedFile == null) {
return new Result( lang.get( "exPlsUpload" ) );
}
if (Uploader.IsImage( postedFile ))
return Uploader.SaveImg( postedFile );
return Uploader.SaveFile( postedFile );
}
开发者ID:robin88,项目名称:wojilu,代码行数:16,代码来源:Uploader.cs
示例13: isAllowedFile
private static Boolean isAllowedFile( HttpFile pfile )
{
String[] types = { "zip", "7z", "rar" };
String[] cfgTypes = config.Instance.Site.UploadFileTypes;
if (cfgTypes != null && cfgTypes.Length > 0) types = cfgTypes;
foreach (String ext in types) {
if (strUtil.IsNullOrEmpty( ext )) continue;
String extWithDot = ext.StartsWith( "." ) ? ext : "." + ext;
if (strUtil.EqualsIgnoreCase( Path.GetExtension( pfile.FileName ), extWithDot )) return true;
}
return false;
}
开发者ID:robin88,项目名称:wojilu,代码行数:14,代码来源:Uploader.cs
示例14: IsImage
/// <summary>
/// 判断上传文件是否是图片
/// </summary>
/// <param name="postedFile"></param>
/// <returns></returns>
public static Boolean IsImage( HttpFile postedFile )
{
return IsImage( postedFile.ContentType, postedFile.FileName );
}
开发者ID:robin88,项目名称:wojilu,代码行数:9,代码来源:Uploader.cs
示例15: Save
/// <summary>
/// 保存用户上传的头像
/// </summary>
/// <param name="postedFile"></param>
/// <param name="userId"></param>
/// <returns></returns>
public static Result Save( HttpFile postedFile, int userId )
{
return upload_private( sys.Path.DiskAvatar, postedFile, userId );
}
开发者ID:Boshin,项目名称:wojilu,代码行数:10,代码来源:AvatarUploader.cs
示例16: upload_private
private static Result upload_private( String uploadPath, HttpFile postedFile, int userId )
{
logger.Info( "uploadPath:" + uploadPath + ", userId:" + userId );
Result result = new Result();
checkUploadPic( postedFile, result );
if (result.HasErrors) return result;
AvatarSaver aSaver = AvatarSaver.New( postedFile );
return savePicCommon( aSaver, userId, result, uploadPath );
}
开发者ID:Boshin,项目名称:wojilu,代码行数:13,代码来源:AvatarUploader.cs
示例17: SaveImg
/// <summary>
/// 保存上传的图片
/// </summary>
/// <param name="postedFile"></param>
/// <param name="arrThumbType"></param>
/// <returns></returns>
public static Result SaveImg( HttpFile postedFile, Dictionary<String, ThumbInfo> arrThumbType )
{
Result result = new Result();
CheckUploadPic( postedFile, result );
if (result.HasErrors) {
logger.Info( result.ErrorsText );
return result;
}
String pathName = PathHelper.Map( sys.Path.DiskPhoto );
String photoName = Img.GetPhotoName( pathName, postedFile.ContentType );
String filename = Path.Combine( pathName, photoName );
try {
postedFile.SaveAs( filename );
foreach (KeyValuePair<String, ThumbInfo> kv in arrThumbType) {
Boolean isValid = SaveThumbSingle( filename, kv.Key, kv.Value );
if (!isValid) {
file.Delete( filename );
result.Add( "format error: " + postedFile.FileName );
return result;
}
}
}
catch (Exception exception) {
logger.Error( lang.get( "exPhotoUploadError" ) + ":" + exception.Message );
result.Add( lang.get( "exPhotoUploadErrorTip" ) );
return result;
}
result.Info = photoName.Replace( @"\", "/" );
return result;
}
开发者ID:2014AmethystCat,项目名称:wojilu,代码行数:41,代码来源:Uploader.cs
示例18: savePicPrivate
private PhotoPost savePicPrivate( HttpFile postedFile, Result result )
{
PhotoPost post = new PhotoPost();
post.OwnerId = ctx.owner.Id;
post.OwnerType = ctx.owner.obj.GetType().FullName;
post.OwnerUrl = ctx.owner.obj.Url;
post.Creator = (User)ctx.viewer.obj;
post.CreatorUrl = ctx.viewer.obj.Url;
post.DataUrl = result.Info.ToString();
post.Title = strUtil.CutString( Path.GetFileNameWithoutExtension( postedFile.FileName ), 20 );
post.Ip = ctx.Ip;
post.PhotoAlbum = new PhotoAlbum();
postService.CreatePostTemp( post );
return post;
}
开发者ID:LeoLcy,项目名称:cnblogsbywojilu,代码行数:17,代码来源:MbSaveController.cs
示例19: OSHttpRequest
public OSHttpRequest(HttpListenerContext context)
{
_request = context.Request;
_context = context;
if (null != _request.Headers["content-encoding"])
_contentEncoding = Encoding.GetEncoding(_request.Headers["content-encoding"]);
if (null != _request.Headers["content-type"])
_contentType = _request.Headers["content-type"];
_queryString = new NameValueCollection();
_query = new Hashtable();
try
{
foreach (string item in _request.QueryString.Keys)
{
try
{
_queryString.Add(item, _request.QueryString[item]);
_query[item] = _request.QueryString[item];
}
catch (InvalidCastException)
{
MainConsole.Instance.DebugFormat("[OSHttpRequest]: error parsing {0} query item, skipping it",
item);
continue;
}
}
}
catch (Exception)
{
MainConsole.Instance.Error("[OSHttpRequest]: Error parsing querystring");
}
if (ContentType != null && ContentType.StartsWith("multipart/form-data"))
{
HttpMultipart.Element element;
var boundry = "";
var multipart = new HttpMultipart(InputStream, boundry, ContentEncoding ?? Encoding.UTF8);
while ((element = multipart.ReadNextElement()) != null)
{
if (string.IsNullOrEmpty(element.Name))
throw new FormatException("Error parsing request. Missing value name.\nElement: " + element);
if (!string.IsNullOrEmpty(element.Filename))
{
if (string.IsNullOrEmpty(element.ContentType))
throw new FormatException("Error parsing request. Value '" + element.Name +
"' lacks a content type.");
// Read the file data
var buffer = new byte[element.Length];
InputStream.Seek(element.Start, SeekOrigin.Begin);
InputStream.Read(buffer, 0, (int) element.Length);
// Generate a filename
var originalFileName = element.Filename;
var internetCache = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
// if the internet path doesn't exist, assume mono and /var/tmp
var path = string.IsNullOrEmpty(internetCache)
? Path.Combine("var", "tmp")
: Path.Combine(internetCache.Replace("\\\\", "\\"), "tmp");
element.Filename = Path.Combine(path, Math.Abs(element.Filename.GetHashCode()) + ".tmp");
// If the file exists generate a new filename
while (File.Exists(element.Filename))
element.Filename = Path.Combine(path, Math.Abs(element.Filename.GetHashCode() + 1) + ".tmp");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
File.WriteAllBytes(element.Filename, buffer);
var file = new HttpFile
{
Name = element.Name,
OriginalFileName = originalFileName,
ContentType = element.ContentType,
TempFileName = element.Filename
};
Files.Add(element.Name, file);
}
/*else
{
var buffer = new byte[element.Length];
message.Body.Seek(element.Start, SeekOrigin.Begin);
message.Body.Read(buffer, 0, (int)element.Length);
form.Add(Uri.UnescapeDataString(element.Name), message.ContentEncoding.GetString(buffer));
}*/
}
}
}
开发者ID:velus,项目名称:Async-Sim-Testing,代码行数:95,代码来源:OSHttpRequest.cs
示例20: Decode
/// <summary>
/// Decode body stream
/// </summary>
/// <param name="stream">Stream containing the content</param>
/// <param name="contentType">Content type header</param>
/// <param name="encoding">Stream encoding</param>
/// <returns>Decoded data.</returns>
/// <exception cref="FormatException">Body format is invalid for the specified content type.</exception>
/// <exception cref="InternalServerException">Something unexpected failed.</exception>
/// <exception cref="ArgumentNullException"><c>stream</c> is <c>null</c>.</exception>
public DecodedData Decode(Stream stream, ContentTypeHeader contentType, Encoding encoding)
{
if (stream == null)
throw new ArgumentNullException("stream");
if (contentType == null)
throw new ArgumentNullException("contentType");
if (encoding == null)
throw new ArgumentNullException("encoding");
//multipart/form-data, boundary=AaB03x
string boundry = contentType.Parameters["boundary"];
if (boundry == null)
throw new FormatException("Missing boundary in content type.");
var multipart = new HttpMultipart(stream, boundry, encoding);
var form = new DecodedData();
/*
FileStream stream1 = new FileStream("C:\\temp\\mimebody.tmp", FileMode.Create);
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
stream1.Write(bytes, 0, bytes.Length);
stream1.Flush();
stream1.Close();
*/
HttpMultipart.Element element;
while ((element = multipart.ReadNextElement()) != null)
{
if (string.IsNullOrEmpty(element.Name))
throw new FormatException("Error parsing request. Missing value name.\nElement: " + element);
if (!string.IsNullOrEmpty(element.Filename))
{
if (string.IsNullOrEmpty(element.ContentType))
throw new FormatException("Error parsing request. Value '" + element.Name +
"' lacks a content type.");
// Read the file data
var buffer = new byte[element.Length];
stream.Seek(element.Start, SeekOrigin.Begin);
stream.Read(buffer, 0, (int) element.Length);
// Generate a filename
string originalFileName = element.Filename;
string internetCache = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
// if the internet path doesn't exist, assume mono and /var/tmp
string path = string.IsNullOrEmpty(internetCache)
? Path.Combine("var", "tmp")
: Path.Combine(internetCache.Replace("\\\\", "\\"), "tmp");
element.Filename = Path.Combine(path, Math.Abs(element.Filename.GetHashCode()) + ".tmp");
// If the file exists generate a new filename
while (File.Exists(element.Filename))
element.Filename = Path.Combine(path, Math.Abs(element.Filename.GetHashCode() + 1) + ".tmp");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
File.WriteAllBytes(element.Filename, buffer);
var file = new HttpFile
{
Name = element.Name,
OriginalFileName = originalFileName,
ContentType = element.ContentType,
TempFileName = element.Filename
};
form.Files.Add(file);
}
else
{
var buffer = new byte[element.Length];
stream.Seek(element.Start, SeekOrigin.Begin);
stream.Read(buffer, 0, (int) element.Length);
form.Parameters.Add(HttpUtility.UrlDecode(element.Name), encoding.GetString(buffer));
}
}
return form;
}
开发者ID:rafavg77,项目名称:MissVenom,代码行数:94,代码来源:MultiPartDecoder.cs
注:本文中的HttpFile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论