I am having a node/express ecosystem of apps and at some point I need to move a file that is uploaded to one of the machines, that is storing this file and copy it to another one.
Those two machines are running two different services of the ecosystem. Lets call them, reception service and utilities service
Here is how I am doing it.
I am sending a plain AJAX request from reception to utilities
request({
method: 'GET',
url: the_utilities_url
},
(err, response, body) => {
if (err) {
// Logic and callback invocation
}
// More logic and callback invocation
})
At the utilities side I just do
return res.sendFile(path_to_the_file)
When printing the response I get, I can see the contents of the exe(regardless of how readable they are).
Later on, upon return from the request to utilities, I am doing
fs.writeFile(target_path, data_retrieved, a_callback_function)
The resulted file has different size and md5 checksum than the original one. Of course, invoking the it raises an error. I have also tried the same, but the data were wrapped by Buffer.from
So, my question is: How can I transfer an exe file from a machine to another machine, without invoking scp? As it is working for other file types, like text files, what is that I am doing wrong for binaries?
request defaults response to utf-8 format, you must specify encoding: null
to receive a proper binary Buffer.
Side Note: this method will buffer the entire file in memory, consider using streamed response if working with large files.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.