/// <summary>Gets the given request.</summary> /// /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null.</exception> /// <exception cref="FilterInvalidBodyAccessException">Thrown when a Filter Invalid Body Access error condition occurs.</exception> /// /// <param name="request">The request.</param> /// /// <returns>An object.</returns> public object Get(FileUpload request) { if (request.RelativePath.IsNullOrEmpty()) throw new ArgumentNullException("RelativePath"); var filePath = ("~/" + request.RelativePath).MapHostAbsolutePath(); if (!File.Exists(filePath)) throw new FilterInvalidBodyAccessException(request.RelativePath); var result = new HttpResult(new FileInfo(filePath)); return result; }
/// <summary>Post this message.</summary> /// /// <exception cref="ValidationError">Thrown when a validation error error condition occurs.</exception> /// /// <param name="request">The request.</param> /// /// <returns>An object.</returns> public object Post(FileUpload request) { if (this.RequestContext.Files.Length == 0) throw new ValidationError("UploadError", "No such file exists"); var file = this.RequestContext.Files[0]; return new FileUploadResponse { FileName = file.FileName, ContentLength = file.ContentLength, ContentType = file.ContentType, Contents = new StreamReader(file.InputStream).ReadToEnd(), }; }