ipfs 上传图片音视频

import { NFTStorage, File } from "nft.storage";
const apiKey = ‘’
 
 
this.client = new NFTStorage({ token: apiKey })
 
async uploadIpfsImage(data, fileType) {
      let filename = `${new Date().getTime() + fileType}`
      this.uploadImageDisable = true
      try {
        const metadata = await this.client.store({
          name: 'PlaNFT',
          description: 'PlaNFT',
          image: new File([data], filename),
        })
        let url = metadata.data.image.href
        this.characterValue = url.replace('ipfs://', 'https://ipfs.io/ipfs/')
        // 预览图片
        let imageReader = new FileReader();
        imageReader.readAsDataURL(data);
        imageReader.onload = () => {
          this.characterPreview = imageReader.result;
        };
      } catch (error) {
        console.log('[ error ] >', error)
        this.$message.error('nft storage error')
      }
      this.uploadImageDisable = false
    },
posted @ 2022-01-10 11:09  起风了1573  阅读(199)  评论(0)    收藏  举报