Automate the uploading of images from a folder

Former Member
Former Member

How would I achieve a setup whereby I have a physical folder on the website where I transferred images by FTP., and the images are automatically taken from the folder and uploaded into the site using the Drag and Drop facility? this would happen automatically, and uploaded images would be deleted from the folder. Would an automation work here? Can an automation process files in a folder?

Parents Reply Children
  • You can embedded in HTML (via [view] or <img src="..." />).

  • Former Member
    0 Former Member in reply to Brian Dooley

    I wrote some code to upload files from a folder on my computer to the temp folder, but I'm getting the following error message "Access to upload files is denied." Here's the code:

    	class Program
        {
            static void Main(string[] args)
            {
                const string USER_NAME = "admin";
                const string OAUTH_CLIENT_ID = "";
                const string OAUTH_SECRET = "";
                var host = new ClientCredentialsRestHost(USER_NAME, "http://localhost/", OAUTH_CLIENT_ID, OAUTH_SECRET);
        
                string[] files = Directory.GetFiles("C:\\PSP", "*.jpg");
    
                foreach (string f in files)
                {
    
                    using (var fileStream = new FileStream(f, FileMode.Open, FileAccess.Read))
                    {
                        fileStream.Position = 0;
                        Guid uploadContextId = Guid.NewGuid();
                        UploadedFile file = new UploadedFile(uploadContextId, f, "image/jpg", fileStream);
    
                        UploadedFileInfo fileInfo = host.UploadFile(file, new RestFileOptions()
                        {
                            UploadProgress = (p) =>
                            {
                                Console.WriteLine("Percent Complete:" + p.PercentComplete);
                            }
                        });
    
                        //if (!fileInfo.IsError)
                        //{
                        //    Create
                        //}
                    }
                }
            }
        }

    I also tried a different approach as follows:

       class Program
        {
            static void Main(string[] args)
            {
                const string USER_NAME = "admin";
                const string OAUTH_CLIENT_ID = "";
                const string OAUTH_SECRET = "";
                var host = new ClientCredentialsRestHost(USER_NAME, "http://localhost/", OAUTH_CLIENT_ID, OAUTH_SECRET);
        
                string[] files = Directory.GetFiles("C:\\PSP", "*.jpg");
    
                foreach (string f in files)
                {
    
                        Guid uploadContextId = Guid.NewGuid();
                        var response = host.PostToDynamic(2, "cfs/temporary.json", false, new RestPostOptions
                        {
                            PostParameters = new NameValueCollection {
                            { "UploadContextId",  uploadContextId.ToString() },
                            { "FileName", f }
                            }
                        });
    
                    Console.WriteLine(response.Errors[0]);
    
                }
            }
        }

    with this approach I'm getting the following error message:

    "Errors, no file was found in the request or the file could not be read.".