Skip to content

Commit

Permalink
Merge pull request #438 from jgangemi/jae/issue-434
Browse files Browse the repository at this point in the history
- added overloaded 'uploadAsset' method
  • Loading branch information
kohsuke authored Aug 30, 2018
2 parents 7bf23ea + eacdd7a commit c413fc1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/org/kohsuke/github/GHRelease.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -125,12 +126,16 @@ static GHRelease[] wrap(GHRelease[] releases, GHRepository owner) {
* handling of the HTTP requests to github's API.
*/
public GHAsset uploadAsset(File file, String contentType) throws IOException {
return uploadAsset(file.getName(), new FileInputStream(file), contentType);
}

public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException {
Requester builder = new Requester(owner.root);

String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s",
owner.getApiTailUrl(""), getId(), file.getName());
owner.getApiTailUrl(""), getId(), filename);
return builder.contentType(contentType)
.with(new FileInputStream(file))
.with(stream)
.to(url, GHAsset.class).wrap(this);
}

Expand Down

0 comments on commit c413fc1

Please sign in to comment.