@@ -243,12 +243,46 @@ private async Task<string> PostFileDataAsync(string destinationUrl, string conte
243
243
HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( destinationUrl ) ;
244
244
245
245
byte [ ] bytes ;
246
- if ( Uri . IsWellFormedUriString ( contentOrFilePath , UriKind . RelativeOrAbsolute ) )
247
- bytes = File . ReadAllBytes ( contentOrFilePath ) ;
248
- else if ( new Uri ( contentOrFilePath ) . IsFile )
249
- bytes = File . ReadAllBytes ( new Uri ( contentOrFilePath ) . LocalPath ) ;
246
+ if ( System . IO . Path . IsPathRooted ( contentOrFilePath ) )
247
+ {
248
+ // The string looks like a file path, so try to read the file
249
+ if ( System . IO . File . Exists ( contentOrFilePath ) )
250
+ {
251
+ bytes = System . IO . File . ReadAllBytes ( contentOrFilePath ) ;
252
+ }
253
+ else
254
+ {
255
+ // The file does not exist, so treat the string as content
256
+ bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
257
+ }
258
+ }
259
+ else if ( Uri . IsWellFormedUriString ( contentOrFilePath , UriKind . RelativeOrAbsolute ) )
260
+ {
261
+ // The string looks like a URI, so try to parse it as a file URI
262
+ var uri = new Uri ( contentOrFilePath ) ;
263
+ if ( uri . IsFile )
264
+ {
265
+ if ( System . IO . File . Exists ( uri . LocalPath ) )
266
+ {
267
+ bytes = System . IO . File . ReadAllBytes ( uri . LocalPath ) ;
268
+ }
269
+ else
270
+ {
271
+ // The file does not exist, so treat the string as content
272
+ bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
273
+ }
274
+ }
275
+ else
276
+ {
277
+ // The URI is not a file URI, so treat the string as content
278
+ bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
279
+ }
280
+ }
250
281
else
282
+ {
283
+ // The string is not a file path or a URI, so treat it as content
251
284
bytes = System . Text . Encoding . UTF8 . GetBytes ( contentOrFilePath ) ;
285
+ }
252
286
253
287
request . ContentType = LinqHelper . GetEnumMemberValue ( contentType ) ;
254
288
request . ContentLength = bytes . Length ;
0 commit comments