第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

找不到已刪除的圖像

找不到已刪除的圖像

SMILET 2021-04-09 13:15:45
我在節(jié)點(diǎn)JS服務(wù)器上編寫的函數(shù)不會(huì)刪除該圖像。他找不到圖片。但是,當(dāng)您鍵入圖片名稱時(shí),它會(huì)從文件夾中刪除它。我收到此錯(cuò)誤:無法刪除本地映像:錯(cuò)誤:ENOENT:沒有此類文件或目錄,請(qǐng)取消鏈接“ C:\ Users \ mary \ Desktop \ Node.js-UploadFiles-RestAPIs \ uploads \ undefined”NodeJS:文件控制器const uploadFolder = __basedir + '/uploads/';const fs = require('fs');exports.deleteFile=(req, res)=> {    let filename = req.params.filename;    fs.unlink(uploadFolder + filename, (err) => {        if (err) {            console.log("failed to delete local image:"+err);        } else {            console.log('successfully deleted local image');                                        }});}NodeJS:文件路由器let express = require('express');let router = express.Router();let fileWorker = require('../controllers/file.controller.js');router.delete('/api/file/delete', fileWorker.deleteFile);module.exports = router; Service.ts:    delete(file : File):Observable<HttpEvent<{}>>{      // const formdata: FormData = new FormData();      // formdata.append('file' , file);      const req = new HttpRequest('DELETE', 'http://localhost:8000/api/file/delete',file, {        responseType: 'text'      });      return this.http.request(req);    }component.ts:  x:any[];  deleteImage(y){  // @ts-ignore  this.x=getFile();    this.imageServis.delete(y).subscribe(event => {      console.log("Here");    });}
查看完整描述

1 回答

?
嗶嗶one

TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊

看到錯(cuò)誤中的未定義:


'C:\ Users \ mary \ Desktop \ Node.js-UploadFiles-RestAPIs \ uploads \ undefined'


文件名未在您的函數(shù)中定義:


exports.deleteFile=(req, res)=> {


    let filename = req.params.filename;

    fs.unlink(uploadFolder + filename, (err) => {

您使用了req.params,但似乎您在正文中發(fā)送了文件名:


 const req = new HttpRequest('DELETE', 'http://localhost:8000/api/file/delete',file, {

    responseType: 'text'


  });

如果要使用req.params,請(qǐng)執(zhí)行以下操作:


 const req = new HttpRequest('DELETE', 'http://localhost:8000/api/file/delete'+file,null, {

    responseType: 'text'


  });



router.delete('/api/file/delete/:filename', fileWorker.deleteFile);


查看完整回答
反對(duì) 回復(fù) 2021-04-22
  • 1 回答
  • 0 關(guān)注
  • 159 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)