i need some assistance trying handle some changes ...
# cfml-general
d
i need some assistance trying handle some changes i need to make to some posts in a database. In these said posts, there could be an image tag that I need to update the src reference for if that source reference contains
/siteRepository
, if it does, update that to now point to an AWS S3 location where the image will be located at. as of right now, I know how to get the image tags, and I'm able to get the file name from the src because I'll need that. I just don't know how to go about handling the updating of all matches that get returned and then have the post updated with these changes. As of right now, this is all I've been able to come up with.
Copy code
regexp = "<img\s[^>]*?src\s*=\s*['\""](\/siteRepository\/[^'\""]*?)['\""][^>]*?>";
    fileRegexp = "\/userfiles\/(.+)";

    contentPagePosts.each(
        function(struct row, numeric rowNumber, query query) {
            <!--- Take the body of the post and replace the img src to point to S3 bucket location --->
            currentPostBody = row.body;
            currentSchoolId = row.schoolid;

            <!--- Find all image references in the post body --->
            <!--- images is an array that has length (len), match, and position (pos) --->
            images = reFindNoCase(regexp, currentPostBody, 1, true, "all");

            <!--- Loop through images arrays --->
            images.each(function(element, index) {
                if (element.match[1] NEQ "") {
                    fileName = "";

                    <!--- Retrieve the file name --->
                    element.match[2].each(function(e, i) {
                        findFileName = reFindNoCase(fileRegexp, e, 1, true, "all");
                        fileName = findFileName[1].match[2];

                        writeDump(e);
                        writeDump(fileName);
                    });

                    writeDump(element);
                }
            });

            <!--- Update the body value with the updated data --->

            //writeDump(images);

            //newPostBody = reReplaceNoCase(currentPostBody, regexp, "#s3LinkBase##currentSchoolId#/userfiles/", "ALL");
        },
        false,
        500
    );
An example post would be something like
Copy code
<p style="text-align: center;"><img alt="" src="/siteRepository/203/userfiles/Hoodie.jpg" style="width: 100px; height: 133px;" /></p>

<p style="text-align: center;">Woodgrove Hoodie (Blue)<br />
$40<br />
S, M, XL</p>

<hr />
<p style="text-align: center;"><img alt="" src="/siteRepository/203/userfiles/hat.jpg" style="width: 100px; height: 133px;" /></p>

<p style="text-align: center;">Woodgrove Hats<br />
Adjustable (Blue)<br />
$20<br />
MD, XL</p>

<hr />
<p style="text-align: center;"><img alt="" src="/siteRepository/203/userfiles/greenhat.jpg" style="width: 100px; height: 133px;" /></p>

<p style="text-align: center;">Woodgrove Hats (Green)<br />
$20<br />
LG, XL</p>

<p>&nbsp;</p>
d
Hi @Dustin Lennon, I may be off base here for your situation, but I'd suggest having only the unique relative part of the image URL in the post itself, and supplying the common server part in a method that takes that as its input. That lets you move the whole storage location easily, potentially even changing the tech used to store it. We semi-recently did a major file server server upgrade, where we had to do this for a bunch of different categories of file system locations. We built a fileLocations api, infrastructure to allow those paths to be different in dev than production, and a test fixture to make sure that all expected locations existed and were readable and/or writable as needed. As each category of location moved to a new file server, we just updated the api and tested. Those actual moves were completely free of drama, since the groundwork was in place. HTH.