-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from marccampbell/large-release-upload
Upload and release, to support large files
- Loading branch information
Showing
2 changed files
with
104 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package util | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func UploadFile(fullpath string, url string) error { | ||
file, err := os.Open(fullpath) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
req, err := http.NewRequest("PUT", url, file) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fi, err := os.Stat(fullpath) | ||
if err != nil { | ||
return err | ||
} | ||
req.ContentLength = fi.Size() | ||
|
||
req.Header.Set("Content-Type", "application/x-yaml") | ||
|
||
res, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if res.StatusCode != http.StatusOK { | ||
return err | ||
} | ||
|
||
return nil | ||
} |