public virtual string GetFileUrl(AUFileRecord file, int targetSize = 0, bool showDefaultPicture = true, string storeLocation = null, AUFileTypeEnum defaultFileType = AUFileTypeEnum.Entity) { string url = string.Empty; byte[] fileBinary = null; if (file != null) fileBinary = LoadFileBinary(file); if (file == null || fileBinary == null || fileBinary.Length == 0) { //TODO: phase I no default images for files //if (showDefaultPicture) //{ // url = GetDefaultPictureUrl(targetSize, defaultPictureType, storeLocation); //} return url; } string lastPart = GetFileExtensionFromMimeType(file.MimeType); if (file.IsNew) { //NJM: No thumbs for files //DeletePictureThumbs(picture); //we do not validate picture binary here to ensure that no exception ("Parameter is not valid") will be thrown file = UpdateFile(file.Id, fileBinary, file.MimeType, //file.SeoFilename, file.AltAttribute, file.TitleAttribute, false, false); } //NJM: File name not used because it is not known at time upload button is hit //TODO: infer title from some aspect of document? //string fileName = !String.IsNullOrEmpty(file.TitleAttribute) ? // string.Format("{0}_{1}.{2}", file.Id.ToString("0000000"), file.TitleAttribute, lastPart) : // string.Format("{0}.{1}", file.Id.ToString("0000000"), lastPart); string fileName = string.Format("{0}_0.{1}", file.Id.ToString("0000000"), lastPart); fileName = "AUConsignor" + fileName; //url = GetThumbUrl(fileName, storeLocation); url = storeLocation + "/content/files/" + fileName; return url; /* lock (s_lock) { //string seoFileName = picture.SeoFilename; // = GetPictureSeName(picture.SeoFilename); //just for sure string fileName = file.TitleAttribute; if (targetSize == 0) { thumbFileName = !String.IsNullOrEmpty(fileName) ? string.Format("{0}_{1}.{2}", file.Id.ToString("0000000"), fileName, lastPart) : string.Format("{0}.{1}", file.Id.ToString("0000000"), lastPart); var thumbFilePath = GetThumbLocalPath(thumbFileName); if (!File.Exists(thumbFilePath)) { File.WriteAllBytes(thumbFilePath, pictureBinary); } } else { thumbFileName = !String.IsNullOrEmpty(seoFileName) ? string.Format("{0}_{1}_{2}.{3}", picture.Id.ToString("0000000"), seoFileName, targetSize, lastPart) : string.Format("{0}_{1}.{2}", picture.Id.ToString("0000000"), targetSize, lastPart); var thumbFilePath = GetThumbLocalPath(thumbFileName); if (!File.Exists(thumbFilePath)) { using (var stream = new MemoryStream(pictureBinary)) { Bitmap b = null; try { //try-catch to ensure that picture binary is really OK. Otherwise, we can get "Parameter is not valid" exception if binary is corrupted for some reasons b = new Bitmap(stream); } catch (ArgumentException exc) { _logger.Error(string.Format("Error generating picture thumb. ID={0}", picture.Id), exc); } if (b == null) { //bitmap could not be loaded for some reasons return url; } using (var destStream = new MemoryStream()) { var newSize = CalculateDimensions(b.Size, targetSize); ImageBuilder.Current.Build(b, destStream, new ResizeSettings { Width = newSize.Width, Height = newSize.Height, Scale = ScaleMode.Both, Quality = _mediaSettings.DefaultImageQuality }); var destBinary = destStream.ToArray(); File.WriteAllBytes(thumbFilePath, destBinary); b.Dispose(); } } } } } */ }
// int //GetFileUrl(Model, 100, true) //GetFileUrl(Nop.Plugin.Misc.AUConsignor.Domain.AUFileRecord file, int, bool, string, Nop.Plugin.Misc.AUConsignor.Domain.AUFileTypeEnum)' public virtual string GetFileUrl(int fileId, int targetSize = 0, bool showDefaultPicture = true, string storeLocation = null, AUFileTypeEnum defaultFileType = AUFileTypeEnum.Entity) { var file = GetFileById(fileId); return GetFileUrl(file, targetSize, showDefaultPicture, storeLocation, defaultFileType); }