Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transfer a big file in golang

Tags:

go

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?

like image 866
clinyong Avatar asked Apr 24 '14 15:04

clinyong


1 Answers

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.

like image 135
kostix Avatar answered Oct 27 '22 10:10

kostix