Virtual directory not included in the image's urls

Posted: April 02, 2015 at 3:17 AM Quote #142917
Hi,

If am running nopCommerce under the IIS virtual directory (for example shop.com/nopcommerce/) the images inserted from the Roxy Fileman into the WYSIWYG editor do not contain the virtual directory which results into 404 of course.

The same issue reported here: http://www.nopcommerce.com/boards/t/32133/solved-upload-with-roxy-fileman.aspx#135998.

Thanks
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: April 02, 2015 at 5:35 AM Quote #142923
Hi,

Thanks for reporting. This is a known issue - https://github.com/nopSolutions/nopCommerce/issues/142. It's already stated in the \Administration\Views\Shared\EditorTemplates\RichEditor.cshtml file
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Interested in the dedicated Premium support services provided by core developers? Please visit http://www.nopcommerce.com/supportservices.aspx

Regards,
Andrei Mazulnitsyn
Posted: May 20, 2016 at 8:31 AM Quote #168083
Hi, Do we have any update on the same, using nopCommerce 3.40?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: May 20, 2016 at 11:28 AM Quote #168101
No. This work item is still open
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Interested in the dedicated Premium support services provided by core developers? Please visit http://www.nopcommerce.com/supportservices.aspx

Regards,
Andrei Mazulnitsyn
Posted: October 27, 2016 at 6:21 AM Quote #177873
recently I have to work with this issue and following fixes it with Roxyfileman:
this is how i did it though can be refactored:

Webconfig:  <add key="ImageVirtualDirectory" value="D:/temp/vdirs"/>
it works differently if on network:
<add key="ImageVirtualDirectory" value="////Nasserv01/shared/test"/>

conf.json:
    "FILES_ROOT": "~/Content/Images/uploaded", // set it to your virtual image directory


RoxyFilemanController

        private string confFile = "~/Content/Roxy_Fileman/conf.json"; // if IIS has an issue with json otherwise not needed
        private string rootDirectory = "~/content/images/uploaded";


        private static readonly string ImageVirtualDirectory = ConfigurationManager.AppSettings["ImageVirtualDirectory"];
        private const string ImageVirtualDirectoryName = "Content"; // or whatever

   private string FixPath(string path)
        {
            if (path == null)
                path = "";

            if (!path.StartsWith("~"))
            {
                if (!path.StartsWith("/"))
                    path = "/" + path;
                path = "~" + path;
            }
            path = path.Replace("\\", "/");
            if (!string.IsNullOrEmpty(ImageVirtualDirectory) && path.Contains(ImageVirtualDirectory))
            {
                path = path.Replace(ImageVirtualDirectory, ImageVirtualDirectoryName);
            }
            if (!path.ToLowerInvariant().Contains(rootDirectory))
                path = rootDirectory;
            return _context.Server.MapPath(path);
        }

        protected void ListDirTree(string type)
        {
            DirectoryInfo d = new DirectoryInfo(GetFilesRoot());
            if (!d.Exists)
                throw new Exception("Invalid files root directory. Check your configuration.");

            ArrayList dirs = ListDirs(d.FullName);
            dirs.Insert(0, d.FullName);

            string localPath = _context.Server.MapPath("~/");
            _r.Write("[");
            for (int i = 0; i < dirs.Count; i++)
            {
                string dir = (string)dirs[i];
                _r.Write("{\"p\":\"/" + dir.Replace(localPath, "").Replace("\\", "/").Replace(ImageVirtualDirectory, "Content") + "\",\"f\":\"" + GetFiles(dir, type).Count.ToString() + "\",\"d\":\"" + Directory.GetDirectories(dir).Length.ToString() + "\"}");
                if (i < dirs.Count - 1)
                    _r.Write(",");
            }
            _r.Write("]");
        }


protected void ListFiles(string path, string type)
        {
            CheckPath(path);
            string fullPath = FixPath(path);
            List<string> files = GetFiles(fullPath, type);
            _r.Write("[");
            var virtualPath = fullPath.Replace("\\", "/");
            if (virtualPath.Contains(ImageVirtualDirectory))
            {
                path = virtualPath.Replace(ImageVirtualDirectory, "/Content");
            }
// remaining code



// for network virtual path
private string FixPath(string path)
  {

      if (!path.StartsWith("~")){
      if (!path.StartsWith("/"))
        path = "/" + path;
      path = "~" + path;
    }

        path = path.Replace("\\", "/");
        if (!string.IsNullOrEmpty(ImageVirtualDirectory) && path.Contains(ImageVirtualDirectory))
        {
            path = path.Replace(ImageVirtualDirectory, ImageVirtualDirectoryName);
        }
        if (!path.ToLowerInvariant().Contains(rootDirectory))
            path = rootDirectory;
                
    return _context.Server.MapPath(path);
  }

  protected void ListDirTree(string type)
  {
    DirectoryInfo d = new DirectoryInfo(GetFilesRoot());
    if(!d.Exists)
      throw new Exception("Invalid files root directory. Check your configuration.");

    ArrayList dirs = ListDirs(d.FullName);
    dirs.Insert(0, d.FullName);

    string localPath = _context.Server.MapPath("~/");
    _r.Write("[");
    for(int i = 0; i <dirs.Count; i++){
      string dir = (string) dirs[i];

        var newPath = "{\"p\":\"/" +
                      dir.Replace(localPath, "").Replace("\\", "/") +
                      "\",\"f\":\"" + GetFiles(dir, type).Count.ToString() + "\",\"d\":\"" +
                      Directory.GetDirectories(dir).Length.ToString() + "\"}";
        newPath = newPath.Replace("///", "////").Replace(ImageVirtualDirectory, "/Content/files");
            _r.Write(newPath);
      if(i < dirs.Count -1)
        _r.Write(",");
    }
    _r.Write("]");
  }

  protected void ListFiles(string path, string type)
  {
    CheckPath(path);
    string fullPath = FixPath(path);
    List<string> files = GetFiles(fullPath, type);
    _r.Write("[");


        var virtualPath = fullPath.Replace("\\", "/");
        if (virtualPath.Contains(ImageVirtualDirectory))
        {
            path = virtualPath.Replace(ImageVirtualDirectory, "/Content/files");
        }
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: October 27, 2016 at 11:26 PM Quote #177918
[quote=asn]...this is how i did it though can be refactored.../quote]
Thanks a lot for this conribution! We'll check it
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Interested in the dedicated Premium support services provided by core developers? Please visit http://www.nopcommerce.com/supportservices.aspx

Regards,
Andrei Mazulnitsyn
Posted: May 18, 2017 at 6:51 AM Quote #187927
Hi. Was it fixed in any version?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.
E-COMMERCE CONFERENCE 2017
Learn more