2020-12-01 14:43

support: How to us to upload to S3 (github file upload)

Hi Nick,

This really just a support request (don't think it is a bug) ... if you have time to answer or sample code to point me to.

I'm working on making a script to take my gh-pages branch and upload itto github

They use a two part POST technique described here: http://developer.github.com/v3/repos/downloads/

Here's some of my code -- the first POST using HTTParty works and I get back valid json.

class Github
  include HTTParty
  base_uri 'https://api.github.com/repos/concord-consortium/lab'
  format :json
  basic_auth CONFIG[:username], CONFIG[:password]

tag = `git log -1 --date=short --format=%cd-%h gh-pages`.strip
name = "lab-dist-#{tag}.tar.gz"
if File.exist?("uploads/#{name}") || system("git archive gh-pages | gzip >uploads/#{name}")
  options = {
    "name" => name,
    "size" => File.stat("uploads/#{name}").size,
    "description" => "Latest release of Lab distribution",
    "content_type" => "application/x-gzip"
  response = Github.post('/downloads', :body => MultiJson.encode(options))
  pp response

This is the part that doesn't work:

url = URI.parse(response['s3_url'])
File.open("#{PROJECT_ROOT}/uploads/#{name}") do |archive|
  req = Net::HTTP::Post::Multipart.new url.path,
    'key'            => response['path'],
    'acl'            => response['acl'],
    'success_action_status' => 201,
    'Filename'       => response['name'],
    'AWSAccessKeyId' => response['accesskeyid'],
    'Policy'         => response['policy'],
    'Signature'      => response['signature'],
    'Content-Type'   => response['mime_type'],
    "file"           => UploadIO.new(archive, response['mime_type'])
  res = Net::HTTP.start(url.host, url.port) do |http|

I'm pretty sure thats NOT how to add the extra parameters for the multipart post -- but I didn't see an example combining the file and the other form' elements.

Thanks for any help!


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39828193 weixin_39828193 5月前

    I haven't got back to it yet. Probably will in the next two weeks. I did get this response from github support. When I add uploading project artifact scripts to our work I'll take a look at this suggestion and perhaps my original code. If I find out what was wrong with my earlier script I'll update this thread.

    From: Rick (GitHub Staff) Subject: Ruby example for uploading to repo downloads

    Sure, this is using my Faraday gem (0.8)


    点赞 评论 复制链接分享
  • weixin_39632698 weixin_39632698 5月前

    It would be helpful if there were something in the README about non-file params. Like stepheneb said above - I was pretty sure that's not how to add more parameters into the multipart post. I spent a lot of time browsing the methods trying to figure it out - but yes, it's just that easy.

    点赞 评论 复制链接分享
  • weixin_39628271 weixin_39628271 5月前

    No, that's actually exactly how you do it. What error(s) are you seeing?

    点赞 评论 复制链接分享
  • weixin_39828193 weixin_39828193 5月前

    I've put the code and response in the console here: https://gist.github.com/2198834

    点赞 评论 复制链接分享
  • weixin_39628271 weixin_39628271 5月前

    Curious, did you ever get this to work? I can't figure out what the issue is here. The error is confusing, because on line 59 you are passing 2 arguments even though it's claiming you're only passing 1.

    点赞 评论 复制链接分享