【问题标题】:How to save blob url image in folder using express?如何使用 express 将 blob url 图像保存在文件夹中?
【发布时间】:2020-06-19 01:24:23
【问题描述】:

您好,我在请求中有此输入

{
  "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!");
}); 

那么's 看起来像这样

【问题讨论】:

    标签: node.js file blob react-admin


    【解决方案1】:
    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!");
    }); 
    

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

    【讨论】:

    猜你喜欢
    • 2020-11-19
    • 2013-06-23
    • 1970-01-01
    • 2020-12-17
    • 2019-09-21
    • 2018-01-29
    • 2022-01-12
    • 1970-01-01
    • 2021-08-12
    相关资源
    最近更新 更多