<?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>DEV Community: Shefali </title>
    <description>The latest articles on DEV Community by Shefali  (@shefalii).</description>
    <link>https://dev.to/shefalii</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%2F1462823%2F0744eaff-53b1-4760-a7df-92ad30fdea6f.jpeg</url>
      <title>DEV Community: Shefali </title>
      <link>https://dev.to/shefalii</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shefalii"/>
    <language>en</language>
    <item>
      <title>🎨🖌️Digital Collaborative Sketchbook: A Web App for Creating and Storing Art ✎</title>
      <dc:creator>Shefali </dc:creator>
      <pubDate>Mon, 14 Oct 2024 06:14:25 +0000</pubDate>
      <link>https://dev.to/shefalii/digital-collaborative-sketchbook-a-web-app-for-creating-and-storing-art-44i0</link>
      <guid>https://dev.to/shefalii/digital-collaborative-sketchbook-a-web-app-for-creating-and-storing-art-44i0</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6r7kbdvuh697rvkkv6u.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6r7kbdvuh697rvkkv6u.jpg" alt="Image description" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/pinata"&gt;The Pinata Challenge &lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;I created a web application that allows users to draw digital sketches and upload them to Pinata for storage on the IPFS network. The application features a user-friendly drawing interface with various tools, including colors and brush sizes. Once a sketch is complete, users can download it as an image file and upload it to Pinata, ensuring that their artwork is securely stored and easily accessible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;You can try out my application (demo) [&lt;a href="https://sketchbook-pinata-client.vercel.app/" rel="noopener noreferrer"&gt;https://sketchbook-pinata-client.vercel.app/&lt;/a&gt;]&lt;/p&gt;

&lt;h2&gt;
  
  
  My Code
&lt;/h2&gt;

&lt;p&gt;You can view the source code for my project on GitHub: &lt;a href="https://github.com/Shefalidesai/sketchbook-pinata" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  More Details
&lt;/h2&gt;

&lt;p&gt;I utilized Pinata to manage the upload of images generated by the sketching tool. Here are some key features:&lt;/p&gt;

&lt;p&gt;IPFS Uploads: Once a sketch is saved, the image is converted into a Blob and uploaded to Pinata, which provides a secure and decentralized storage solution.&lt;br&gt;
Efficient File Management: Each upload is linked to a specific user (if authentication is implemented), allowing for organized management of their artworks.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Key Implementation Steps:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;How to Obtain a Pinata API Key&lt;/strong&gt;&lt;br&gt;
To integrate Pinata with your project, follow these steps to obtain an API key:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Sign Up or Log In to Pinata:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to &lt;a href="https://pinata.cloud/" rel="noopener noreferrer"&gt;https://pinata.cloud/&lt;/a&gt; and create an account or log in if you already have one.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create an API Key:&lt;br&gt;
After logging in, go to the "API Keys" section in your dashboard.&lt;br&gt;
Click "New Key" to create a new API key.&lt;br&gt;
Provide a name for the key and configure the permissions you need (e.g., pinFileToIPFS for uploading files).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click "Create", and you will receive an API key, secret, and JWT (JSON Web Token). Copy these as they are needed for your project.&lt;br&gt;
Store the API Key Securely:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In your Next.js project, create a .env.local file to store the API key securely:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NEXT_PUBLIC_PINATA_JWT=your_jwt_token_here
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace your_jwt_token_here with the JWT you obtained from Pinata. Ensure that you do not expose this key in your codebase or publicly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How I Built the Sketch App&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Image Conversion: I used the canvas.toDataURL() method to convert the drawn sketch into a Base64 string, which is then transformed into a Blob for uploading.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');

canvas.addEventListener('mousedown', startDrawing);
canvas.addEventListener('mousemove', draw);
canvas.addEventListener('mouseup', stopDrawing);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Pinata Integration: Using the Pinata API, I sent the Blob as a file in a multipart/form-data format. This ensures that the file is properly handled by Pinata, and upon successful upload, users receive a unique IPFS hash for their sketch.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const downloadSketch = () =&amp;gt; {
    const URL = canvas.toDataURL('image/jpeg');
    const anchor = document.createElement('a');
    anchor.href = URL;
    anchor.download = 'sketch.jpg';
    anchor.click();
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const uploadToPinata = async (anchor) =&amp;gt; {
        const token = process.env.NEXT_PUBLIC_PINATA_JWT;

        const form = new FormData();
        const blob = await fetch(anchor.href).then(anchor =&amp;gt; anchor.blob()); 
        const file = new File([blob], 'sketch.jpg', { type: 'image/jpeg' });
        form.append("file", file);

        const options = {
            method: 'POST',
            headers: {
                Authorization: `Bearer ${token}`, 
            },
            body: form            
        };


        try {
            const response = await fetch('https://uploads.pinata.cloud/v3/files', options);
            const data = await response.json();
            if (response.ok) {
                console.log("Upload successful:", data);
                return data; 
            } else {
                console.error("Error uploading to Pinata:", data);
            }
        } catch (error) {
            console.error("Error uploading to Pinata:", error);
        }
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;User Feedback: After each upload, users are notified of the success or failure of the operation, enhancing the user experience.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Screenshots of Uploaded Sketches from the SketchBook App&lt;br&gt;
Below are screenshots that showcase the successful upload of images created using the SketchBook app to Pinata Cloud.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyfy7fov8kwz750he1q06.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyfy7fov8kwz750he1q06.png" alt="Image description" width="800" height="378"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>pinatachallenge</category>
      <category>webdev</category>
      <category>api</category>
    </item>
  </channel>
</rss>
