Example #1
0
        public void Process(FormClientUploadPipelineArgs args)
        {
            if (args.StopProcessing)
            {
                return;
            }

            var isResized = args.FieldParameters.ContainsKey("resizemedia") && args.FieldParameters["resizemedia"] == "yes";

            if (isResized)
            {
                int width = 1000;
                int.TryParse(args.FieldParameters["maxwidth"], out width);

                Log.Info("AzureUploadField: Resizing media to " + width, this);

                string aspectRatioVal;

                args.PostedFile.Data = ResizeMedia(args.PostedFile.Data, 1000, out aspectRatioVal);

                args.AspectRatioValue = aspectRatioVal;

                Log.Info("AzureUploadField: Success" + width, this);
            }
        }
        public void Process(FormClientUploadPipelineArgs args)
        {
            if (args.StopProcessing)
            {
                return;
            }

            Log.Debug("Azure File Upload: Uploading to blob storage...", this);

            string containerName = "default";

            if (args.FieldParameters.ContainsKey("azurecontainer"))
            {
                containerName = args.FieldParameters["azurecontainer"];
            }

            var file = args.PostedFile;

            Log.Debug("Azure File Upload: Container - " + containerName + "File - " + file.FileName + "...", this);

            var url = Upload(containerName, file.FileName, file.Data);

            Log.Debug("Azure File Upload: Success - " + url, this);

            args.ReturnValue = (object)new AzurePostedFile()
            {
                Name        = file.FileName,
                Url         = url,
                AspectRatio = args.AspectRatioValue
            };
        }
Example #3
0
        public void Process(FormClientUploadPipelineArgs args)
        {
            int    _fileSizeLimit = Sitecore.Configuration.Settings.GetIntSetting("AzureUploadField.FileSizeLimit", 10); //2MB
            string _extensions    = Sitecore.Configuration.Settings.GetSetting("AzureUploadField.Extensions", ".jpg,.jpeg,.png,.bmp");

            var  fileUpload = args.PostedFile;
            bool isValid    = true;

            if (args.FieldParameters.ContainsKey("filesizelimit"))
            {
                _fileSizeLimit = int.Parse(args.FieldParameters["filesizelimit"]);
            }

            if (args.FieldParameters.ContainsKey("fileextensions"))
            {
                _extensions = args.FieldParameters["fileextensions"];
            }

            if (fileUpload != null && fileUpload.Data != null)
            {
                Log.Info("AzureUploadField: Validating uploaded media ", this);

                int sizeInBytes = fileUpload.Data.Length;
                int limit       = _fileSizeLimit * 1024 * 1024;
                isValid = (sizeInBytes <= limit);

                Log.Info("AzureUploadField: Validate file size - " + sizeInBytes + " " + limit + " " + isValid, this);

                string[] extensions = _extensions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var      extension  = Path.GetExtension(fileUpload.FileName);
                if (extension != null && !extensions.Contains(extension.ToLower()))
                {
                    isValid = false;
                }

                Log.Info("AzureUploadField: Validate file extension- " + extension + " " + _extensions + " " + isValid, this);
            }

            if (!isValid)
            {
                args.StopProcessing = true;
                args.ReturnValue    = new AzurePostedFile()
                {
                    ValidationError = Translate.Text("Story_Invalid_Image")
                };
            }
        }