Skip to content

Commit

Permalink
Updated PhotoService.Replace to support absolute filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Bruun committed May 6, 2011
1 parent 8abad27 commit d222a99
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
*.ReSharper*
*.ReSharper
_ReSharper*
obj
bin
*.suo
20 changes: 20 additions & 0 deletions 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
6 changes: 5 additions & 1 deletion src/Implementations/PhotoService.cs
Expand Up @@ -355,13 +355,17 @@ public bool Replace(int photoId, string filename, string fileContentType, System
// Build request URL
List<string> requestUrlParameters = new List<string>();

// 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<MultipartPostPart> data = new List<MultipartPostPart>
{
MultipartPostPart.CreateFormPart("photo_id", photoId.ToString()),
MultipartPostPart.CreateFormFilePart("file", filename, fileContentType, filestream)
MultipartPostPart.CreateFormFilePart("file", relativeFilename, fileContentType, filestream)
};

XPathNavigator responseMessage = _provider.DoRequest(requestMessage, data);
Expand Down

0 comments on commit d222a99

Please sign in to comment.