Created
          November 11, 2021 19:16 
        
      - 
      
- 
        Save polluterofminds/218b913de7094d64df5f6cf6acd7c4a4 to your computer and use it in GitHub Desktop. 
    Base64 Without File System
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const { Readable } = require("stream"); | |
| const FormData = require("form-data"); | |
| const axios = require("axios"); | |
| (async () => { | |
| try { | |
| const base64 = "BASE64 FILE STRING; | |
| const imgBuffer = Buffer.from(base64, "base64"); | |
| const stream = Readable.from(imgBuffer); | |
| const data = new FormData(); | |
| data.append('file', stream, { | |
| filepath: 'FILENAME.png' | |
| }) | |
| const res = await axios.post("https://api.pinata.cloud/pinning/pinFileToIPFS", data, { | |
| maxBodyLength: "Infinity", | |
| headers: { | |
| 'Content-Type': `multipart/form-data; boundary=${data._boundary}`, | |
| pinata_api_key: pinataApiKey, | |
| pinata_secret_api_key: pinataSecretApiKey | |
| } | |
| }); | |
| console.log(res.data); | |
| } catch (error) { | |
| console.log(error); | |
| } | |
| })(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment