ipfs.mjs 718 B

12345678910111213141516171819202122232425
  1. import * as randomString from 'randomstring'
  2. import axios from 'axios'
  3. const { data: buffer } = await axios.get('https://cataas.com/cat', {
  4. responseType: 'arraybuffer'
  5. })
  6. const imgUrl = await this.fileService.uploadBuffer(buffer, 'image', 'jpg')
  7. const f = new FormData()
  8. f.append(
  9. 'file',
  10. new Blob([
  11. JSON.stringify({
  12. name: randomString.generate({ length: 8, charset: 'alphanumeric' }),
  13. attributes: [],
  14. image: imgUrl
  15. })
  16. ])
  17. )
  18. const { data: res } = await axios.post('https://ipfs.infura.io:5001/api/v0/add', f, {
  19. auth: {
  20. username: '2RrUoAzIHbABPzXlH4M7Rnc3Fir',
  21. password: 'aaa4218c6944d2b9ad706275e5f1d6f1'
  22. }
  23. })
  24. console.log(res)