<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Chetan </title>
    <description>The latest articles on Forem by Chetan  (@chetan_2708).</description>
    <link>https://forem.com/chetan_2708</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1274291%2F72b27e7f-9568-4544-a8cb-f2b2a5241afa.png</url>
      <title>Forem: Chetan </title>
      <link>https://forem.com/chetan_2708</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/chetan_2708"/>
    <language>en</language>
    <item>
      <title>Cloudinary to s3 bucket db changes</title>
      <dc:creator>Chetan </dc:creator>
      <pubDate>Tue, 27 Feb 2024 06:02:15 +0000</pubDate>
      <link>https://forem.com/chetan_2708/cloudinary-to-s3-bucket-db-changes-241c</link>
      <guid>https://forem.com/chetan_2708/cloudinary-to-s3-bucket-db-changes-241c</guid>
      <description>&lt;p&gt;If you have a database collection that has url field , containing cloudinary or any cloud based platform links and you want to shift/ migrate the urls specifically to s3 bucket then you can use this script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     query = { $regex: /^https:\/\/res\.cloudinary\.com/i }
     const urls = await Audio.find(query).toArray(); 

        const audioList = [];

        // Iterate over each document and process one at a time
        for (const doc of urls) {
            const _id = doc._id;
            const url = doc.url;

                  const filename = path.join("L:/Check Audios", `${_id}.mp3`);

//Function to download and save audio locally 
            await downloadAndSaveAudio(url, filePath);

            // Upload the audio file to S3
            const uploadParams = {
                Bucket: bucketName,
                Key: filename,
                Body: fs.createReadStream(filename),
                ContentType: 'audio/mp3'
            };
            const uploadResponse = await s3Client.send(new PutObjectCommand(uploadParams));

            // Generate S3 URL
            const s3Url = `https://${bucketName}.s3.${bucketRegion}.amazonaws.com/${filename}`;

            // Update the database with the S3 URL
            await Audio.updateOne({ _id: _id }, { $set: { url: s3Url } });

            // Push information to audioList
            audioList.push({ _id: _id, s3Url: s3Url });
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>node</category>
      <category>mongodb</category>
    </item>
    <item>
      <title>Cloudinary to s3 bucket db changes</title>
      <dc:creator>Chetan </dc:creator>
      <pubDate>Tue, 27 Feb 2024 06:02:14 +0000</pubDate>
      <link>https://forem.com/chetan_2708/cloudinary-to-s3-bucket-db-changes-3mp6</link>
      <guid>https://forem.com/chetan_2708/cloudinary-to-s3-bucket-db-changes-3mp6</guid>
      <description>&lt;p&gt;If you have a database collection that has url field , containing cloudinary or any cloud based platform links and you want to shift/ migrate the urls specifically to s3 bucket then you can use this script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     query = { $regex: /^https:\/\/res\.cloudinary\.com/i }
     const urls = await Audio.find(query).toArray(); 

        const audioList = [];

        // Iterate over each document and process one at a time
        for (const doc of urls) {
            const _id = doc._id;
            const url = doc.url;

                  const filename = path.join("L:/Check Audios", `${_id}.mp3`);

//Function to download and save audio locally 
            await downloadAndSaveAudio(url, filePath);

            // Upload the audio file to S3
            const uploadParams = {
                Bucket: bucketName,
                Key: filename,
                Body: fs.createReadStream(filename),
                ContentType: 'audio/mp3'
            };
            const uploadResponse = await s3Client.send(new PutObjectCommand(uploadParams));

            // Generate S3 URL
            const s3Url = `https://${bucketName}.s3.${bucketRegion}.amazonaws.com/${filename}`;

            // Update the database with the S3 URL
            await Audio.updateOne({ _id: _id }, { $set: { url: s3Url } });

            // Push information to audioList
            audioList.push({ _id: _id, s3Url: s3Url });
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>node</category>
      <category>mongodb</category>
    </item>
  </channel>
</rss>
