2017-08-01 90 views
0

在下面的代碼中,我有兩個控制器,它們是upload/post和document/post,並且在API上傳輸時保存file.name時有點困難到秒,有時兩個不匹配,例如數據庫一個是file20170801053331.jpg上傳的圖片將是file20170801053332.jpg因爲,兩個不匹配,所以我打算將文件名轉移到上傳控制器,所以它會是相同的但是file.name不能被改變。如何在上傳之前更改dropzone中的File.Name

const req = request.post('http://localhost:8933/api/upload/post'); 
      acceptedFiles.forEach(file => { 


       var now = new Date().toLocaleString('en-PH'); 
       form.State = 1; 
       var cdate =dateFormat(now, "yyyymmddHHMMs") 
       var ext = file.name.split(".").slice(-1)[0]; 
       var ext2 = file.name.split("."+ext).slice(0)[0]; 
       var fileNames = (ext2+cdate+"." +ext); 
       form.Link=fileNames; 
       form.Name=file.name; 
       file.name = fileNames; // this is what im trying to do but it wasnt working 
       req.attach(file.name, file); 
       this.props.post('document/post', form); 
      }); 
       req.end(callback); 

回答

0

您可以通過在req.attach添加新的名稱改變file.name

var name = form.something.length; 
    var acceptedFiles = form.passFile; 
    const req = request.post('http://localhost:8933/api/upload/post'); 
    acceptedFiles.forEach(file => { 
     form.State = 1; 
     var cdate =uuidv1(); 
     var ext = file.name.split(".").slice(-1)[0]; 
     var ext2 = file.name.split("."+ext).slice(0)[0]; 
     var fileNames = (ext2+cdate+"." +ext); // call this and put it on the req.attach 
     form.Link=fileNames; 
     form.Name=file.name; 
     req.attach(file.name, file, fileNames); 
     this.props.post('document/post', form); 

    }); 
相關問題