Skip to content

Commit

Permalink
- added overloaded 'uploadAsset' method
Browse files Browse the repository at this point in the history
  • Loading branch information
jgangemi committed May 30, 2018
1 parent d61697a commit eacdd7a
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 eacdd7a

Please sign in to comment.