Skip to content

Instantly share code, notes, and snippets.

@stevedylandev
Created October 23, 2022 18:17
Show Gist options
  • Save stevedylandev/89f52a25a7a2701c815c000add7ee671 to your computer and use it in GitHub Desktop.
Save stevedylandev/89f52a25a7a2701c815c000add7ee671 to your computer and use it in GitHub Desktop.
Submarining a File via API
import axios from 'axios'
import FormData from 'form-data'
import fs from 'fs'
const submarineFile = async () => {
const data = new FormData()
data.append(`files`, fs.createReadStream('./path/to/file.png'));
data.append('pinToIPFS', 'false');
try {
const res = await axios.post("https://managed.mypinata.cloud/api/v1/content", data, {
maxBodyLength: "Infinity",
headers: {
'x-api-key': 'submarine_api_key'
}
});
console.log(res.data);
} catch (error) {
console.log(error)
}
};
submarineFile()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment