如何使用Express在文件夹中保存Blob网址图片?

问题描述 投票:0回答:1

嗨,我在请求中有此输入

{
  "title": "Places Search Box",
  "tags": "sd",
  "pictures": {
    "rawFile": {
      "path": "Screenshot 2020-03-05 at 12.05.55 PM.png"
    },
    "banner": "blob:http://localhost:3001/3b3dead6-bee0-4a9c-a0b3-28a560ee1558"
  }
}

我将如何使用node.js将这个Blob URL blob:http://localhost:3001/3b3dead6-bee0-4a9c-a0b3-28a560ee1558图像保存在文件夹中。

当我试图保存这样的内容时

const fs = require('fs');
const myUrl = res.pictures.banner;


fs.writeFile("/myFolder/myFile", myUrl, function(err) {
    if(err) {
        return console.log(err);
    }
    console.log("The file was saved!");
}); 

然后它的enter image description here看起来像这样

node.js file blob react-admin
1个回答
0
投票
const fs = require('fs');

const res = {
  "title": "Places Search Box",
  "tags": "sd",
  "pictures": {
    "rawFile": {
      "path": "Screenshot 2020-03-05 at 12.05.55 PM.png"
    },
    "banner": "blob:http://localhost:3001/3b3dead6-bee0-4a9c-a0b3-28a560ee1558"
  }
}

const myUrl = res.pictures.banner;


fs.writeFile("/myFolder/myFile", myUrl, function(err) {
    if(err) {
        return console.log(err);
    }
    console.log("The file was saved!");
}); 

这很简单,如果您不明白,只问您错过了什么。

© www.soinside.com 2019 - 2024. All rights reserved.