fixing file name issue for linux and possibly mac · b3605ad1de - SVN.BY: Go Git Service
Browse Source

fixing file name issue for linux and possibly mac

Related Work Items: #28
Tiernan OToole 8 years ago
parent
commit
b3605ad1de
1 changed files with 13 additions and 2 deletions
  1. 13 2
      B2Uploader/Program.cs

+ 13 - 2
B2Uploader/Program.cs

@@ -51,7 +51,7 @@ namespace B2Uploader
51 51
                 {
52 52
                     //check if file already exists
53 53
 
54
-                    string fileName = s.Replace('\\', '/');
54
+                    string fileName = getValidFilename(s);
55 55
 
56 56
                     var existingFiles = ListFileNames(new ListFileNamesRequest() { bucketId = bucket.bucketId, startFileName = fileName }, auth.apiUrl, auth.authorizationToken);
57 57
                     bool found = false;
@@ -129,6 +129,15 @@ namespace B2Uploader
129 129
             
130 130
             return JsonConvert.DeserializeObject<GetUploadURLResponse>(responseString);
131 131
         }
132
+        static string getValidFilename(string input)
133
+        {
134
+            string fileName = input.Replace('\\', '/');
135
+            if (fileName.StartsWith("/"))
136
+            {
137
+                fileName = fileName.Substring(1);
138
+            }
139
+            return fileName;
140
+        }
132 141
 
133 142
         static UploadFileResponse UploadFile(string authToken, string contentType, string filePath, string uploadUrl)
134 143
         {
@@ -138,7 +147,9 @@ namespace B2Uploader
138 147
 
139 148
             var headers = GetAuthHeaders(authToken);
140 149
 
141
-            headers.Add(new Tuple<string, string>("X-Bz-File-Name", filePath.Replace('\\', '/')));
150
+            string fileName = getValidFilename(filePath);
151
+
152
+            headers.Add(new Tuple<string, string>("X-Bz-File-Name", fileName));
142 153
             headers.Add(new Tuple<string, string>("X-Bz-Content-Sha1", sha1));
143 154
 
144 155
             string responseString = MakeWebRequest(uploadUrl, headers, bytes, contentType);