-
-
Save xiconet/818a897d3542e5e8443f to your computer and use it in GitHub Desktop.
Revisions
-
xiconet renamed this gist
Oct 25, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
xiconet revised this gist
Oct 25, 2015 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,6 +27,7 @@ func main() { pipeOut, pipeIn := io.Pipe() fsize := stat.Size() fname := stat.Name() bar := pb.New(int(fsize)).SetUnits(pb.U_BYTES) bar.ShowSpeed = true @@ -44,9 +45,8 @@ func main() { return } req.ContentLength = fsize // filesize req.ContentLength += 232 // this value just works req.ContentLength += int64(len(fname)) req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") @@ -61,7 +61,7 @@ func main() { done <- nil }() part, err := writer.CreateFormFile("file", fname) check(err) out := io.MultiWriter(part, bar) -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,7 +46,7 @@ func main() { req.ContentLength = fsize // filesize req.ContentLength += 227 // multipart header exclouding filename req.ContentLength += int64(len(os.Args[1])) req.ContentLength += 19 req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,7 +46,7 @@ func main() { req.ContentLength = fsize // filesize req.ContentLength += 227 // multipart header exclouding filename req.ContentLength += int64(len(os.Args[1])) req.ContentLength -= 19 req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") -
cryptix revised this gist
Jun 22, 2014 . No changes.There are no files selected for viewing
-
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,6 +46,7 @@ func main() { req.ContentLength = fsize // filesize req.ContentLength += 227 // multipart header exclouding filename req.ContentLength += int64(len(os.Args[1])) req.ContentLength += 19 req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,9 +43,9 @@ func main() { done <- err return } req.ContentLength = fsize // filesize req.ContentLength += 227 // multipart header exclouding filename req.ContentLength += int64(len(os.Args[1])) req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,9 +43,9 @@ func main() { done <- err return } // req.ContentLength = fsize // filesize // req.ContentLength += 227 // multipart header exclouding filename // req.ContentLength += int64(len(os.Args[1])) req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -44,7 +44,7 @@ func main() { return } req.ContentLength = fsize // filesize req.ContentLength += 227 // multipart header exclouding filename req.ContentLength += int64(len(os.Args[1])) req.Header.Set("Content-Type", writer.FormDataContentType()) -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,9 +43,9 @@ func main() { done <- err return } req.ContentLength = fsize // filesize req.ContentLength += 225 // multipart header exclouding filename req.ContentLength += int64(len(os.Args[1])) req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,9 +43,9 @@ func main() { done <- err return } // req.ContentLength = fsize // filesize // req.ContentLength += 225 // multipart header exclouding filename // req.ContentLength += int64(len(os.Args[1])) req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -44,8 +44,8 @@ func main() { return } req.ContentLength = fsize // filesize req.ContentLength += 225 // multipart header exclouding filename req.ContentLength += int64(len(os.Args[1])) req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,7 +43,7 @@ func main() { done <- err return } req.ContentLength = fsize // filesize req.ContentLength += 225 // multipart header exclouding filename req.ContentLength += int64(len(fname)) -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,8 @@ func main() { check(err) pipeOut, pipeIn := io.Pipe() fsize := stat.Size() bar := pb.New(int(fsize)).SetUnits(pb.U_BYTES) bar.ShowSpeed = true writer := multipart.NewWriter(pipeIn) -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,6 +42,9 @@ func main() { done <- err return } req.ContentLength = size // filesize req.ContentLength += 225 // multipart header exclouding filename req.ContentLength += int64(len(fname)) req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") @@ -53,7 +56,6 @@ func main() { return } done <- nil }() -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,14 +46,13 @@ func main() { req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") bar.Start() resp, err = http.DefaultClient.Do(req) if err != nil { done <- err return } done <- nil }() -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,6 +46,7 @@ func main() { req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") bar.Start() resp, err = http.DefaultClient.Do(req) if err != nil { done <- err -
cryptix revised this gist
Jun 22, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,7 +35,6 @@ func main() { var resp *http.Response done := make(chan error) go func() { // prepare request req, err := http.NewRequest("POST", "http://localhost:9000/upload", pipeOut) @@ -46,7 +45,7 @@ func main() { req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") bar.Start() resp, err = http.DefaultClient.Do(req) if err != nil { done <- err -
cryptix created this gist
Jun 22, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,82 @@ package main import ( "io" "log" "mime/multipart" "net/http" "os" "path/filepath" "runtime" "github.com/cheggaaa/pb" ) func main() { if len(os.Args) != 2 { log.Println("Usage: pipeUp <filename>\n") os.Exit(1) } input, err := os.Open(os.Args[1]) check(err) defer input.Close() stat, err := input.Stat() check(err) pipeOut, pipeIn := io.Pipe() bar := pb.New(int(stat.Size())).SetUnits(pb.U_BYTES) bar.ShowSpeed = true writer := multipart.NewWriter(pipeIn) // do the request concurrently var resp *http.Response done := make(chan error) go func() { bar.Start() // prepare request req, err := http.NewRequest("POST", "http://localhost:9000/upload", pipeOut) if err != nil { done <- err return } req.Header.Set("Content-Type", writer.FormDataContentType()) log.Println("Created Request") resp, err = http.DefaultClient.Do(req) if err != nil { done <- err return } log.Println("Do() done") done <- nil }() part, err := writer.CreateFormFile("file", filepath.Base(os.Args[1])) check(err) out := io.MultiWriter(part, bar) _, err = io.Copy(out, input) check(err) check(writer.Close()) check(pipeIn.Close()) // need to close the pipe to check(<-done) bar.FinishPrint("Upload done!") } func check(err error) { _, file, line, _ := runtime.Caller(1) if err != nil { log.Fatalf("Fatal from <%s:%d>\nError:%s", file, line, err) } }