图片已保存,但在节点中保存文件后将不显示

时间:2019-04-04 08:09:30

标签: javascript jquery html node.js

我正在上传图像并将其保存到服务器。它们具有完全相同的名称,但最后一个字符为1或2等。当我尝试使用与其他图像完全相同的代码显示图像时,出现错误

  

获取http://www.suburbsdirectory.co.za/images/profiles/5Business1Pic.jpg 404(未找到)

if (profile_image.substring(0, 8) == 'uploads/') {
  fs.copyFile(`public/${profile_image}`, `public/images/profiles/${id}ProfilePic.jpg`, (err) => {
    if (err) {
      console.log(err)
    };
  })
  setTimeout(() => {
    fs.unlink(`public/${business_image1}`, (err) => {
      if (err) {
        console.log(err)
      };
    })
  }, 200)
}

if (business_image1.substring(0, 8) == 'uploads/') {
  fs.copyFile(`public/${business_image1}`, `public/images/profiles/${id}Business1Pic.jpg`, (err) => {
    if (err) {
      console.log(err)
    };
  })
  setTimeout(() => {
    fs.unlink(`public/${business_image1}`, (err) => {
      if (err) {
        console.log(err)
      };
    })
  }, 250)
}

if (business_image2.substring(0, 8) == 'uploads/') {
  fs.copyFile(`public/${business_image2}`, `public/images/profiles/${id}Business2Pic.jpg`, (err) => {
    if (err) {
      console.log(err)
    };
  })
  setTimeout(() => {
    fs.unlink(`public/${business_image2}`, (err) => {
      if (err) {
        console.log(err)
      };
    })
  }, 300)
}

if (business_image3.substring(0, 8) == 'uploads/') {
  fs.copyFile(`public/${business_image3}`, `public/images/profiles/${id}Business3Pic.jpg`, (err) => {
    if (err) {
      console.log(err)
    };
  })
  setTimeout(() => {
    fs.unlink(`public/${business_image3}`, (err) => {
      if (err) {
        console.log(err)
      };
    })
  }, 350)
}

当我保存到数据库字段的链接时,我将“公共”排除在外。这是在jquery中调用图像的代码:

$('#business_image1').attr('src', result[0].business_image1).css('width', `${profileImageWidth}`)
$('#business_image2').attr('src', result[0].business_image2).css('width', `${profileImageWidth}`)
$('#business_image3').attr('src', result[0].business_image3).css('width', `${profileImageWidth}`)

business_image23完美显示,但数字1却没有显示。这是从sql查询中检索到的数据(如前所述,文件已保存。)

business_image1: "/images/profiles/5Business1Pic.jpg"
business_image2: "/images/profiles/5Business2Pic.jpg"
business_image3: "/images/profiles/5Business3Pic.jpg"

以下是已保存的文件:

Files succesfully uploaded

我已经尝试了几个小时,但是无法理解我犯错的地方。

0 个答案:

没有答案