public object Get(FileUpload request) { if (request.RelativePath.IsNullOrEmpty()) throw new ArgumentNullException("RelativePath"); var filePath = ("~/" + request.RelativePath).MapProjectPath(); if (!File.Exists(filePath)) throw new FileNotFoundException(request.RelativePath); var result = new HttpResult(new FileInfo(filePath)); return result; }
public object Post(FileUpload request) { if (this.Request.Files.Length == 0) throw new FileNotFoundException("UploadError", "No such file exists"); if (request.RelativePath == "ThrowError") throw new NotSupportedException("ThrowError"); var file = this.Request.Files[0]; return new FileUploadResponse { FileName = file.FileName, ContentLength = file.ContentLength, ContentType = file.ContentType, Contents = new StreamReader(file.InputStream).ReadToEnd(), CustomerId = request.CustomerId, CustomerName = request.CustomerName }; }