本文整理汇总了C#中HttpFile类的典型用法代码示例。如果您正苦于以下问题:C# HttpFile类的具体用法?C# HttpFile怎么用?C# HttpFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpFile类属于命名空间,在下文中一共展示了HttpFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 + ")" );
}
}
示例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));
}
示例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
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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 + ")" );
}
}
示例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;
}
示例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 );
}
示例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;
}
示例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 );
}
示例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;
}
示例14: IsImage
/// <summary>
/// 判断上传文件是否是图片
/// </summary>
/// <param name="postedFile"></param>
/// <returns></returns>
public static Boolean IsImage( HttpFile postedFile )
{
return IsImage( postedFile.ContentType, postedFile.FileName );
}
示例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 );
}