Import pictures through Excel using manufacturer image URL

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 Jahre weitere
When using a URL link in Excel for uploading images on new/existing products, I'm getting an error (see below).
Here is an example URL of a product I'm attempting to upload and getting the error. Note: Images are being pulled from the manufacturers website, not my site or local/hosting drive.
http://www.americanbassusa.com/Subwoofers/DX-Series-Images/DX/DX-front.jpg

I've used this style of importing before but the only thing I can see a difference in between a URL that works and the one above that doesn't is the image page isn't secure (https). Can someone shed some light? Is this the reasoning I'm getting the error or is there something else that could be going on? Any workaround/


Log level: Error
Short message: Download image failed
Full message:
System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at System.Net.HttpWebRequest.GetResponse()
   at System.Net.WebClient.GetWebResponse(WebRequest request)
   at System.Net.WebClient.DownloadBits(WebRequest request, Stream writeStream)
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
   at System.Net.WebClient.DownloadData(Uri address)
   at Nop.Services.ExportImport.ImportManager.DownloadFile(String urlString, IList`1 downloadedFiles) in C:\andrei\nopcommerce\sources\src\Libraries\Nop.Services\ExportImport\ImportManager.cs:line 790
5 Jahre weitere
It's the invalid character in image name. I had this same thing before. You may need to modify code to fix it.

In my case, I had changed image name.
5 Jahre weitere
Make sure you don't have any leading/trailing spaces in the URL
5 Jahre weitere
Thanks for the suggestions!
The only special characters in the questioned link would be the dashes. "-"
I have uploaded using dashes in the past.

An example of a working link I've used is:
https://static.summitracing.com/global/images/prod/xlarge/cse-5160_xl.jpg

I don't have any leading or trailing spaces.
Any other suggestions?
5 Jahre weitere
I'm scratching my head at this one and would be interested to know what is wrong.

Both urls download fine in a browser but like you say, that first url is causing the issue.

If it helps in any way, here is the code that is causing the issue that I extracted from nopcommerce into a console to investigate:

class Program
{
    static void Main(string[] args)
    {
        const string WorkingUrl = "https://static.summitracing.com/global/images/prod/xlarge/cse-5160_xl.jpg";
        const string NonWorkingUrl = "http://www.americanbassusa.com/Subwoofers/DX-Series-Images/DX/DX-front.jpg";

        try
        {
            using (var client = new WebClient())
            {
                byte[] fileData = client.DownloadData(NonWorkingUrl);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
            
        Console.ReadLine();
    }
}


If you are still having no luck, it may help to structure this code as a post on stackoverflow to see if anyone can help there.
5 Jahre weitere
I have raised this also as a question on StackOverflow which can be found here:

https://stackoverflow.com/questions/55765880/why-do-i-get-an-exception-when-using-webclient-downloaddata-for-a-url
5 Jahre weitere
As indicated in the answer to the StackOverflow question, the server is expecting a useragent header to check that you are downloading the url from a web browser.

Editing the console application above (which replicates the image download part of nopcommerce):

using (var client = new WebClient())
{
    client.Headers.Add(System.Net.HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134");
    byte[] fileData = client.DownloadData("http://www.americanbassusa.com/Subwoofers/DX-Series-Images/DX/DX-front.jpg")
}


will now work.


Therefore, to resolve your problem I would either:

Download all of your required images to your machine and reference the actual paths instead.  You may be able to find an application to help download images from a server.

OR

Override the ImportManager.DownloadFile(string, IList<string>) method of nopcommerce to add the header above.


Hope this helps.
5 Jahre weitere
Curious...Could you throw this link in your test.

https://cdn.shopify.com/s/files/1/1885/9927/products/21028a_600x_crop_center.jpg

I'm not sure if this was the exact link I was having issues with, but it seemed it was one from this CDN.
5 Jahre weitere
The link https://cdn.shopify.com/s/files/1/1885/9927/products/21028a_600x_crop_center.jpg appears to work regardless of whether you provide the header or not.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.