From d222a993d117cffb6d8f3ad51732b2cdbd01ec16 Mon Sep 17 00:00:00 2001 From: Nick Bruun Date: Fri, 6 May 2011 10:57:54 +0200 Subject: [PATCH] Updated PhotoService.Replace to support absolute filenames --- .gitignore | 6 ++++++ src/23API.sln | 20 ++++++++++++++++++++ src/Implementations/PhotoService.cs | 6 +++++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 src/23API.sln diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7af7693 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.ReSharper* +*.ReSharper +_ReSharper* +obj +bin +*.suo \ No newline at end of file diff --git a/src/23API.sln b/src/23API.sln new file mode 100644 index 0000000..2ffeac5 --- /dev/null +++ b/src/23API.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Web Developer Express 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "23API", "23API.csproj", "{DE4C51D3-D764-410A-A34C-D6DA6EEAE35A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DE4C51D3-D764-410A-A34C-D6DA6EEAE35A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE4C51D3-D764-410A-A34C-D6DA6EEAE35A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE4C51D3-D764-410A-A34C-D6DA6EEAE35A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE4C51D3-D764-410A-A34C-D6DA6EEAE35A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/Implementations/PhotoService.cs b/src/Implementations/PhotoService.cs index 464d471..db95764 100644 --- a/src/Implementations/PhotoService.cs +++ b/src/Implementations/PhotoService.cs @@ -355,13 +355,17 @@ public bool Replace(int photoId, string filename, string fileContentType, System // Build request URL List requestUrlParameters = new List(); + // Ensure that only relative filenames are sent + int relativeFilenameSplit = filename.LastIndexOf('\\'); + string relativeFilename = (relativeFilenameSplit == -1 ? filename : filename.Substring(relativeFilenameSplit + 1)); + // Do the request MessageReceivingEndpoint requestMessage = new MessageReceivingEndpoint(_provider.GetRequestUrl("/api/photo/replace", requestUrlParameters), HttpDeliveryMethods.PostRequest | HttpDeliveryMethods.AuthorizationHeaderRequest); List data = new List { MultipartPostPart.CreateFormPart("photo_id", photoId.ToString()), - MultipartPostPart.CreateFormFilePart("file", filename, fileContentType, filestream) + MultipartPostPart.CreateFormFilePart("file", relativeFilename, fileContentType, filestream) }; XPathNavigator responseMessage = _provider.DoRequest(requestMessage, data);