nopCommerce icon indicating copy to clipboard operation
nopCommerce copied to clipboard

Possible error downloading files when importing products

Open RomanovM opened this issue 3 years ago • 2 comments

nopCommerce version: 4.30

The Uri.IsWellFormedUriString function sometimes returns a false negative depending on the characters in the URI (see https://github.com/dotnet/runtime/issues/21626). In my case some image file names had the ^ character in it. The workaround I am using is to url encode the image string before checking if it is a valid uri. I also had to change uri kind from Absolute to RelativeOrAbsolute for it to work.

In the Nop.Services/ExportImport/ImportManager.cs file I changed the function DownloadFile as follows:

Before:

if (!Uri.IsWellFormedUriString(urlString, UriKind.Absolute))
  return urlString;

After:

var encodedUrl = System.Web.HttpUtility.UrlEncode(urlString);
if (!Uri.IsWellFormedUriString(encodedUrl, UriKind.RelativeOrAbsolute))
  return urlString;

Source: https://www.nopcommerce.com/boards/topic/79591/product_picture_mapping-issue#280288

RomanovM avatar Jan 25 '21 08:01 RomanovM

Decided not to come up with workarounds and wait for dotnet team to fix this bug.

RomanovM avatar Jan 27 '21 09:01 RomanovM

We are waiting for a solution to the #72632 ticket from the dotnet team

skoshelev avatar Jan 30 '23 12:01 skoshelev