Amazon MWS SubmitFeed Content-MD5 HTTP header did not match the Content-MD5 calculated by Amazon

前端 未结 4 1088
故里飘歌
故里飘歌 2021-01-07 17:18

I know this question is not new but all the solution I get for this are in PHP or my issue is different from them.

I am using MWS feed API to submit flat file for Pr

4条回答
  •  悲&欢浪女
    2021-01-07 17:51

    Amazon requires the md5 hash of the file in base64 encoding.

    Your code:

    var fileReadStream = fs.createReadStream('/path/to/file.txt');
    var file = fileReadStream.toString('base64'); //'[object Object]'
    var contentMD5Value = crypto.createHash('md5').update(file).digest('base64');
    

    wrongly assumes that a readStream's toString() will produce the file contents, when, in fact, this method is inherited from Object and produces the string '[object Object]'.

    Base64-encoding that string always produces the 'FEGnkJwIfbvnzlmIG534uQ==' that you mentioned.

    If you want to properly read and encode the hash, you can do the following:

    var fileContents = fs.readFileSync('/path/to/file.txt'); // produces a byte Buffer
    var contentMD5Value = crypto.createHash('md5').update(fileContents).digest('base64'); // properly encoded
    

    which provides results equivalent to the following PHP snippet:

    $contentMD5Value = base64_encode(md5_file('/path/to/file.txt', true));
    

提交回复
热议问题