是否可以获取从服务器下载的文件的 md5 哈希值?



是否可以在将文件存储到 mongo databse 之前,使用从服务器下载的 mongo grid fs 获取文件的 md5 哈希值。现在使用下面的代码,它使用md5,文件名,内容类型等将数据直接存储到mongo,因为我使用了pipe。现在我想先检查文件的md5哈希值,然后再将其存储到数据库,我想首先获取文件的md5值,因为我想使用它来避免重复。现在我确实尝试记录文件存储。但我不认为它包含MD5。知道吗?谢谢。顺便说一句,我正在使用蒙戈网格fs

文件存储数据

GridWriteStream{ 
_writableState:WritableState{ 
objectMode:false,
highWaterMark:16384,
finalCalled:false,
needDrain:false,
ending:false,
ended:false,
finished:false,
destroyed:false,
decodeStrings:true,
defaultEncoding:'utf8',
length:0,
writing:false,
corked:0,
sync:true,
bufferProcessing:false,
onwrite:[ 
Function:         bound onwrite
],
writecb:null,
writelen:0,
bufferedRequest:null,
lastBufferedRequest:null,
pendingcb:0,
prefinished:false,
errorEmitted:false,
emitClose:true,
autoDestroy:false,
bufferedRequestCount:0,
corkedRequestsFree:{ 
next:null,
entry:null,
finish:[ 
Function:            bound onCorkedFinish
]
}
},
writable:true,
_events:[ 
Object:      null prototype
]{ 
},
_eventsCount:0,
_maxListeners:undefined,
_opened:false,
_opening:true,
_writable:true,
_closing:false,
_destroyed:false,
_errorEmitted:false,
_grid:Grid{ 
db:Db{ 
_events:[ 
Object:            null prototype
]{ 
},
_eventsCount:0,
_maxListeners:undefined,
s:[ 
Object
],
serverConfig:[ 
Getter
],
bufferMaxEntries:[ 
Getter
],
databaseName:[ 
Getter
]
},
mongo:{ 
[ 
Function
]         MongoError:[ 
Function
],
Admin:[ 
Function
],
MongoClient:[ 
Function
],
Db:[ 
Function
],
Collection:[ 
Function
],
Server:[ 
Function
],
ReplSet:[ 
Function
],
Mongos:[ 
Function
],
ReadPreference:[ 
Function
],
GridStore:[ 
Function
],
Chunk:[ 
Function
],
Logger:[ 
Function
],
Cursor:[ 
Function
],
GridFSBucket:[ 
Function
],
CoreServer:[ 
Function
],
CoreConnection:[ 
Function
],
Binary:[ 
Function
],
Code:[ 
Function
],
Map:[ 
Function
],
DBRef:[ 
Function
],
Double:[ 
Function
],
Int32:[ 
Function
],
Long:[ 
Function
],
MinKey:[ 
Function
],
MaxKey:[ 
Function
],
ObjectID:[ 
Function
],
ObjectId:[ 
Function
],
Symbol:[ 
Function
],
Timestamp:[ 
Function
],
Decimal128:[ 
Function
],
connect:[ 
Circular
],
instrument:[ 
Function
]
},
curCol:'fs'
},
options:{ 
filename:'f9bd6032ceae47a8b8b9be07a5dc839e.jpg',
data:'1'
},
name:'f9bd6032ceae47a8b8b9be07a5dc839e.jpg',
id:5d9eef3dde7cc73550be84d8,
mode:'w',
_store:GridStore{ 
db:Db{ 
_events:[ 
Object:            null prototype
]{ 
},
_eventsCount:0,
_maxListeners:undefined,
s:[ 
Object
],
serverConfig:[ 
Getter
],
bufferMaxEntries:[ 
Getter
],
databaseName:[ 
Getter
]
},
referenceBy:1,
fileId:5d9eef3dde7cc73550be84d8,
filename:'f9bd6032ceae47a8b8b9be07a5dc839e.jpg',
mode:'w',
options:{ 
filename:'f9bd6032ceae47a8b8b9be07a5dc839e.jpg',
data:'1'
},
isOpen:false,
root:'fs',
position:0,
readPreference:'primary',
writeConcern:{ 
w:1
},
internalChunkSize:261120,
promiseLibrary:[ 
Function:         Promise
],
chunkSize:[ 
Getter/Setter
],
md5:[ 
Getter
],
chunkNumber:[ 
Getter
]
},
_delayedWrite:null,
_delayedFlush:null,
_delayedClose:null
}

下载文件的代码

var download = function (url, dest, filename callback) {
const file = filename
const fileStorage = gfs.createWriteStream({ filename: file});
// request.get(url)
//     .on('error', function (err) { console.log(err) })
//     .pipe(fileStorage)
//     .on('close', callback);
};
final_list.forEach(function (str) {
var filename = str.split('/').pop();
console.log('Downloading ' + filename);
download(str, filename, function () { console.log('Finished Downloading' + "" + filename) });
});
Solution:

阅读链接

窗户:

1. Download the latest version of WinMD5Free.
2. Extract the downloaded zip and launch the WinMD5.exe file.
3. Click on the Browse button, navigate to the file that you want to check and select it.
4. Just as you select the file, the tool will show you its MD5 checksum.
5. Copy and paste the original MD5 value provided by the developer or the download page.
Click on Verify button.

MAC:

1. Download the file you want to check and open the download folder in Finder.
2. Open the Terminal, from the Applications / Utilities folder.
3. Type md5 followed by a space. Do not press Enter yet.
4. Drag the downloaded file from the Finder window into the Terminal window.
5. Press Enter and wait a few moments.
6. The MD5 hash of the file is displayed in the Terminal.
7. Open the checksum file provided on the Web page where you downloaded your file from.
8. The file usually has a .cksum extension.
NOTE: The file should contain the MD5 sum of the download file. For example: md5sum: 25d422cc23b44c3bbd7a66c76d52af46

9. Compare the MD5 hash in the checksum file to the one displayed in the Terminal.
10. If they are exactly the same, your file was downloaded successfully. Otherwise, download your file again.

LINUX:

1. Open a terminal window.
2. Type the following command: md5sum [type file name with extension here] [path of the file] -- 
NOTE: You can also drag the file to the terminal window instead of typing the full path.
3. Hit the Enter key.
4. You’ll see the MD5 sum of the file. 
5. Match it against the original value.

最新更新