I'm trying to automate uploading a zip file to a release on a repo on github. I'm using github_api to interact with Github's api. I can create a release via that library, but when I try to upload my zip file only the first 425 bytes are transferred. Here's my code related to uploading the file:
files = Dir["<dir_containing_zipefile>"]
files.each do |file|
github.repos.releases.assets.upload "Owner", "Repo", id, File.absolute_path(file),
name: "#{File.basename file}",
content_type: "application/zip"
end
I get the id
from a previous request and have ensured that is correct. I've also ensured that the file found is the correct file (both basename and absolute_path). The request succeeds, but the file uploaded is only a partial of the entire file.
File on system:
File after upload to github release:
After downloading the file from github, I noticed that the 425 Bytes are the first 425 Bytes of my build.zip, but then it seems to get truncated. Has anyone run into this before?
Using Net::HTTP
require 'net/http'
require 'json'
def attach(url, zipFilePath)
data = File.open(zipFilePath, "rb") { |f| f.read }
uri = URI.parse(url)
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{YOUR_GITHUB_ACCESS_TOKEN}"
request.content_type = 'application/zip'
request.body = data
response = Net::HTTP.start(uri.hostname, uri.port, { use_ssl: true }) { |http| http.request(request) }
return JSON.parse(response.body)
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.