在golang中传输大文件 [英] Transfer a big file in golang
问题描述
将从设备保存临时文件到自己吗?我不希望它发生,因为它会减慢上传速度并浪费从属的内存。
有什么办法可以避免这种情况?在golang中传输大文件的最佳方式是什么?
是的,有一种标准方法可以避免存储前向方法:一旦客户端连接了从服务器,后者应该打开一个到主服务器的连接,然后在那里从客户端流数据 。通常这是通过使用 io.Copy()
函数完成的。感谢Go的出色的使用接口的鸭子打字,这适用于TCP连接和HTTP请求/响应。
(为了得到更好的解释,您必须缩小问题的范围。)
解决方案的一部分甚至会出现在由stackoverflow建议的类似问题中— 这里是。
Client send file, the size may be more than 5G, to slave server, and than slave send to master server.
Will the slave save temp file to itself? I do not want it happen because it will slow the upload speed and waste the slave's memory.
Any way to avoid this? And what is the best way to transfer a big file in golang?
Yes, there's a standard way to avoid store-and-forward approach: as soon as a client connects the slave server the latter should open a connection to the master server and then just stream the data from the client there. Typically this is done using the io.Copy()
function. Thanks to Go's excellent duck typing using interfaces, this works for TCP connections and HTTP requests/responses.
(To get better explanation(s) you have to narrow your question down.)
A part of the solution does even appear in the similar questions suggested by stackoverflow—here it is.
这篇关于在golang中传输大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!