public ByteFile(byte[] data, string fileName, string mimeType = null) { if (data.Length == 0) { throw new ArgumentException("Argument is empty collection", nameof(data)); } Data = data; FileName = fileName ?? "file"; MimeType = mimeType ?? BinaryType.GetFileMimeType(FileName); }
public ByteFile(string filePath) { if (File.Exists(filePath)) { Data = File.ReadAllBytes(filePath); if (Data.Length > MaxFileSize) { throw new Exception("file is above {MaxFileSize} bytes. "); } FileName = System.IO.Path.GetFileName(filePath); MimeType = BinaryType.GetFileMimeType(filePath); } else { throw new FileNotFoundException("File is not exists", nameof(filePath)); } }
public BytePostParameter(string name, byte[] value, string fileName = null, string mimeType = null) : base(name, value) { FileName = fileName ?? "attachment"; MimeType = mimeType ?? BinaryType.GetFileMimeType(FileName); }