public override bool CanHandleMedia(int parentNodeId, PostedMediaFile postedFile, User user)
        {
            // Decide whether this factory applies; If not, another factory will be used (i.e. the base class)
            bool isGalleryParent = false;

            if (parentNodeId != -1)
            {
                Media parent = new Media(parentNodeId);
                isGalleryParent = parent.ContentType.Alias == FUND_MEDIA_TYPE + "Folder";
            }
            else
            {
                isGalleryParent = false;
            }

            return(isGalleryParent && base.CanHandleMedia(parentNodeId, postedFile, user));
        }
Ejemplo n.º 2
0
 public Media HandleMedia(int parentNodeId, PostedMediaFile postedFile, User user, bool replaceExisting)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 3
0
 public Media HandleMedia(int parentNodeId, PostedMediaFile postedFile, User user)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 4
0
        public void ProcessUploadRequest(HttpContext context, XmlTextWriter xmlTextWriter)
        {
            int parentNodeId;

            if (int.TryParse(context.Request["parentNodeId"], out parentNodeId) && context.Request.Files.Count > 0)
            {
                try
                {
                    // Check Path
                    if (!string.IsNullOrEmpty(context.Request["path"]))
                    {
                        var pathParts = context.Request["path"].Trim('/').Split('/');

                        var parentNode = new Media(parentNodeId);
                        foreach (var pathPart in pathParts)
                        {
                            if (!string.IsNullOrEmpty(pathPart))
                            {
                                parentNode = GetOrCreateFolder(parentNode, pathPart);
                            }
                        }
                        parentNodeId = parentNode.Id;
                    }

                    // Check whether to replace existing
                    bool replaceExisting = (context.Request["replaceExisting"] == "1");

                    // loop through uploaded files
                    for (var j = 0; j < context.Request.Files.Count; j++)
                    {
                        // get the current file
                        var uploadFile = context.Request.Files[j];

                        // if there was a file uploded
                        if (uploadFile.ContentLength > 0)
                        {
                            var postedMediaFile = new PostedMediaFile
                            {
                                FileName      = uploadFile.FileName,
                                ContentType   = uploadFile.ContentType,
                                ContentLength = uploadFile.ContentLength,
                                InputStream   = uploadFile.InputStream
                            };

                            // Get concrete MediaFactory
                            var factory = MediaFactory.GetMediaFactory(parentNodeId, postedMediaFile, AuthenticatedUser);

                            // Handle media Item
                            var media = factory.HandleMedia(parentNodeId, postedMediaFile, AuthenticatedUser, replaceExisting);
                        }
                    }

                    // log succes
                    Log.Add(LogTypes.New, parentNodeId, "Succes");
                }
                catch (Exception e)
                {
                    // log error
                    Log.Add(LogTypes.Error, parentNodeId, e.ToString());
                }
            }
            else
            {
                // log error
                Log.Add(LogTypes.Error, -1, "Parent node id is in incorrect format");
            }
        }
        public UploadResponse ProcessUploadRequest(HttpContext context)
        {
            int parentNodeId;

            if (int.TryParse(context.Request["parentNodeId"], out parentNodeId) && context.Request.Files.Count > 0)
            {
                try
                {
                    var parentNode = new Media(parentNodeId);
                    // Check FilePath
                    if (!string.IsNullOrEmpty(context.Request["path"]))
                    {
                        var pathParts = context.Request["path"].Trim('/').Split('/');

                        foreach (var pathPart in pathParts.Where(part => string.IsNullOrWhiteSpace(part) == false))
                        {
                            parentNode = GetOrCreateFolder(parentNode, pathPart);
                        }

                        parentNodeId = parentNode.Id;
                    }

                    // Check whether to replace existing
                    bool parsed;
                    var  replaceExisting = (context.Request["replaceExisting"] == "1" || (bool.TryParse(context.Request["replaceExisting"], out parsed) && parsed));

                    // loop through uploaded files
                    for (var j = 0; j < context.Request.Files.Count; j++)
                    {
                        // get the current file
                        var uploadFile = context.Request.Files[j];

                        //Are we allowed to upload this?
                        var ext = uploadFile.FileName.Substring(uploadFile.FileName.LastIndexOf('.') + 1).ToLower();
                        if (UmbracoConfig.For.UmbracoSettings().Content.DisallowedUploadFiles.Contains(ext))
                        {
                            LogHelper.Warn <MediaUploader>("Cannot upload file " + uploadFile.FileName + ", it is not approved in `disallowedUploadFiles` in ~/config/UmbracoSettings.config");
                            continue;
                        }

                        using (var inputStream = uploadFile.InputStream)
                        {
                            // if there was a file uploded
                            if (uploadFile.ContentLength > 0)
                            {
                                // Ensure we get the filename without the path in IE in intranet mode
                                // http://stackoverflow.com/questions/382464/httppostedfile-filename-different-from-ie
                                var fileName = uploadFile.FileName;
                                if (fileName.LastIndexOf(@"\") > 0)
                                {
                                    fileName = fileName.Substring(fileName.LastIndexOf(@"\") + 1);
                                }

                                fileName = Umbraco.Core.IO.IOHelper.SafeFileName(fileName);

                                var postedMediaFile = new PostedMediaFile
                                {
                                    FileName        = fileName,
                                    DisplayName     = context.Request["name"],
                                    ContentType     = uploadFile.ContentType,
                                    ContentLength   = uploadFile.ContentLength,
                                    InputStream     = inputStream,
                                    ReplaceExisting = replaceExisting
                                };

                                // Get concrete MediaFactory
                                var factory = MediaFactory.GetMediaFactory(parentNodeId, postedMediaFile, AuthenticatedUser);

                                // Handle media Item
                                var media = factory.HandleMedia(parentNodeId, postedMediaFile, AuthenticatedUser);
                            }
                        }
                    }

                    var scripts = new ClientTools(new Page());
                    scripts.SyncTree(parentNode.Path, true);

                    // log succes
                    LogHelper.Info <MediaUploader>(string.Format("Success uploading to parent {0}", parentNodeId));
                }
                catch (Exception e)
                {
                    // log error
                    LogHelper.Error <MediaUploader>(string.Format("Error uploading to parent {0}", parentNodeId), e);
                }
            }
            else
            {
                // log error
                LogHelper.Warn <MediaUploader>(string.Format("Parent node id is in incorrect format: {0}", parentNodeId));
            }

            return(new UploadResponse());
        }
Ejemplo n.º 6
0
        public UploadResponse ProcessUploadRequest(HttpContext context)
        {
            int parentNodeId;

            if (int.TryParse(context.Request["parentNodeId"], out parentNodeId) && context.Request.Files.Count > 0)
            {
                try
                {
                    var parentNode = new Media(parentNodeId);
                    // Check FilePath
                    if (!string.IsNullOrEmpty(context.Request["path"]))
                    {
                        var pathParts = context.Request["path"].Trim('/').Split('/');

                        foreach (var pathPart in pathParts)
                        {
                            if (!string.IsNullOrEmpty(pathPart))
                            {
                                parentNode = GetOrCreateFolder(parentNode, pathPart);
                            }
                        }
                        parentNodeId = parentNode.Id;
                    }

                    // Check whether to replace existing
                    var  parsed          = false;
                    bool replaceExisting = (context.Request["replaceExisting"] == "1" || (bool.TryParse(context.Request["replaceExisting"], out parsed) && parsed));

                    // loop through uploaded files
                    for (var j = 0; j < context.Request.Files.Count; j++)
                    {
                        // get the current file
                        var uploadFile = context.Request.Files[j];

                        // if there was a file uploded
                        if (uploadFile.ContentLength > 0)
                        {
                            // Ensure we get the filename without the path in IE in intranet mode
                            // http://stackoverflow.com/questions/382464/httppostedfile-filename-different-from-ie
                            var fileName = uploadFile.FileName;
                            if (fileName.LastIndexOf(@"\") > 0)
                            {
                                fileName = fileName.Substring(fileName.LastIndexOf(@"\") + 1);
                            }

                            fileName = Umbraco.Core.IO.IOHelper.SafeFileName(fileName);

                            var postedMediaFile = new PostedMediaFile
                            {
                                FileName        = fileName,
                                DisplayName     = context.Request["name"],
                                ContentType     = uploadFile.ContentType,
                                ContentLength   = uploadFile.ContentLength,
                                InputStream     = uploadFile.InputStream,
                                ReplaceExisting = replaceExisting
                            };

                            // Get concrete MediaFactory
                            var factory = MediaFactory.GetMediaFactory(parentNodeId, postedMediaFile, AuthenticatedUser);

                            // Handle media Item
                            var media = factory.HandleMedia(parentNodeId, postedMediaFile, AuthenticatedUser);
                        }
                    }

                    var scripts = new ClientTools(new Page());
                    scripts.SyncTree(parentNode.Path, true);

                    // log succes
                    Log.Add(LogTypes.New, parentNodeId, "Succes");
                }
                catch (Exception e)
                {
                    // log error
                    Log.Add(LogTypes.Error, parentNodeId, e.ToString());
                }
            }
            else
            {
                // log error
                Log.Add(LogTypes.Error, -1, "Parent node id is in incorrect format");
            }



            return(new UploadResponse());
        }