/// <summary> /// 将自身作为multipart/form-data的一个文件项 /// </summary> /// <param name="stream">数据流</param> /// <param name="fileName">文件友好名称</param> /// <exception cref="ArgumentNullException"></exception> public MulitpartFile(Stream stream, string fileName) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } this.stream = stream; this.FileName = fileName; this.ContentType = MimeTable.GetContentType(fileName); }
/// <summary> /// multipart/form-data的一个文件项 /// </summary> /// <param name="localFilePath">本地文件路径</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="FileNotFoundException"></exception> public MulitpartFile(string localFilePath) { if (string.IsNullOrEmpty(localFilePath)) { throw new ArgumentNullException(nameof(localFilePath)); } if (File.Exists(localFilePath) == false) { throw new FileNotFoundException(localFilePath); } this.filePath = localFilePath; this.FileName = Path.GetFileName(localFilePath); this.ContentType = MimeTable.GetContentType(localFilePath); }