Skip to content

Commit 15d91a2

Browse files
authored
Merge pull request #453 from RenzoF/main
2 parents 4bcb45a + 19eb75b commit 15d91a2

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

Source/FikaAmazonAPI/Services/FeedService.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,46 @@ private async Task<string> PostFileDataAsync(string destinationUrl, string conte
243243
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);
244244

245245
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+
}
250281
else
282+
{
283+
// The string is not a file path or a URI, so treat it as content
251284
bytes = System.Text.Encoding.UTF8.GetBytes(contentOrFilePath);
285+
}
252286

253287
request.ContentType = LinqHelper.GetEnumMemberValue(contentType);
254288
request.ContentLength = bytes.Length;

0 commit comments

Comments
 (0)