fixing file name issue for linux and possibly mac · b3605ad1de - SVN.BY: Go Git Service
Przeglądaj źródła

fixing file name issue for linux and possibly mac

Related Work Items: #28
Tiernan OToole 8 lat temu
rodzic
commit
b3605ad1de
1 zmienionych plików z 13 dodań i 2 usunięć
  1. 13 2
      B2Uploader/Program.cs

+ 13 - 2
B2Uploader/Program.cs

51
                 {
51
                 {
52
                     //check if file already exists
52
                     //check if file already exists
53
 
53
 
54
-                    string fileName = s.Replace('\\', '/');
54
+                    string fileName = getValidFilename(s);
55
 
55
 
56
                     var existingFiles = ListFileNames(new ListFileNamesRequest() { bucketId = bucket.bucketId, startFileName = fileName }, auth.apiUrl, auth.authorizationToken);
56
                     var existingFiles = ListFileNames(new ListFileNamesRequest() { bucketId = bucket.bucketId, startFileName = fileName }, auth.apiUrl, auth.authorizationToken);
57
                     bool found = false;
57
                     bool found = false;
129
             
129
             
130
             return JsonConvert.DeserializeObject<GetUploadURLResponse>(responseString);
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
         static UploadFileResponse UploadFile(string authToken, string contentType, string filePath, string uploadUrl)
142
         static UploadFileResponse UploadFile(string authToken, string contentType, string filePath, string uploadUrl)
134
         {
143
         {
138
 
147
 
139
             var headers = GetAuthHeaders(authToken);
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
             headers.Add(new Tuple<string, string>("X-Bz-Content-Sha1", sha1));
153
             headers.Add(new Tuple<string, string>("X-Bz-Content-Sha1", sha1));
143
 
154
 
144
             string responseString = MakeWebRequest(uploadUrl, headers, bytes, contentType);
155
             string responseString = MakeWebRequest(uploadUrl, headers, bytes, contentType);