node【UTF-8】解码出错,悬而未决

上传压缩包文件名为【A你你】,node后端获取到文件名变成了【A浣犱綘】。欢迎大神留言指导。
前端文件上传的post请求信息如下:
在这里插入图片描述
服务器端代码如下:
采用iconv尝试了多种编码和解码方法,还是没能正确还原字符串。对照了utf-8汉字编码是正确的,解码结果不正确。

 			var  buf = new Buffer( file.name.split('.')[0], 'UTF-8');  
            // console.log(buf.toString('UTF-8'));         
            console.log(buf);
            buf = iconv.decode(buf,'UTF-8');           
            console.log(buf);
            // var temp = iconv.decode(buf,'utf-8');
            console.log("gbkBytes======================="); 
            var gbkBytes = iconv.encode(file.name.split('.')[0],'gbk');            
            console.log(gbkBytes);
            gbkBytes = iconv.decode(gbkBytes,'gbk');
            console.log(gbkBytes);  
            console.log("binary=======================");            
            var binary = iconv.encode(file.name.split('.')[0],'binary');  
            console.log(binary);     
            binary =  iconv.decode(binary,'UTF-8');
            console.log(binary);          
            console.log("end======================="); 

后台输出如下

utf-8编码=======================
<Buffer 41 e4 bd a0 e4 bd a0>
QeS9oOS9oA==
gbk编码=======================
<Buffer 41 c4 e3 c4 e3>
A浣犱綘
binary编码=======================
<Buffer 41 60 60>
A``
end=======================

具体文件信息如下:

File {
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  size: 160462,
  path: '/tmp/upload_c4ec9eb09f55db9e6d2efce19760e034',
  name: 'A浣犱綘.rar',
  type: 'application/octet-stream',
  hash: null,
  lastModifiedDate: 2019-01-04T02:09:54.482Z,
  _writeStream: 
   WriteStream {
     _writableState: 
      WritableState {
        objectMode: false,
        highWaterMark: 16384,
        finalCalled: false,
        needDrain: false,
        ending: true,
        ended: true,
        finished: true,
        destroyed: false,
        decodeStrings: true,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: false,
        bufferProcessing: false,
        onwrite: [Function: bound onwrite],
        writecb: null,
        writelen: 0,
        bufferedRequest: null,
        lastBufferedRequest: null,
        pendingcb: 0,
        prefinished: true,
        errorEmitted: false,
        bufferedRequestCount: 0,
        corkedRequestsFree: [Object] },
     writable: false,
     domain: null,
     _events: {},
     _eventsCount: 0,
     _maxListeners: undefined,
     path: '/tmp/upload_c4ec9eb09f55db9e6d2efce19760e034',
     fd: null,
     flags: 'w',
     mode: 438,
     start: undefined,
     autoClose: true,
     pos: undefined,
     bytesWritten: 160462,
     closed: true } }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值