如何从网址下载图像,并将加载的图像发布到现有的API?

时间:2015-04-21 02:43:17

标签: ruby ajax post

我想从输入标签获取URL的值,然后执行ajax发布,从URL下载图像,并将加载的图像发布到现有API(API仅支持发布文件)。 / p>

这是我到目前为止所做的:

HTML:

<form id="formSubmit" method="post" target="1">
      <input id="urlInput" type="text" name="url" placeholder="Please input url of picture.">
</form>

<button class="submitBtnUrl"></button>

使用Javascript:

$('.submitBtnUrl').on('click', function() {
    $('#formSubmit').submit(function(event) {
        searchClothesUrl();
        return false;
    });
});

function searchClothesUrl(url){
    $.ajax({
        url: '/search_clothes_url',
        data: {
            'url': /url
        },
        type: 'post',
        success: function(data){

            };
        }
    })
};

post '/url' 
do
    halt 400 unless params[:url]

    =begin
    How can i do to submit the loaded image to the api?
    =end

    payload = {
        :upload => File.new(fn, 'rb')
    }
    result = JSON.parse RestClient::Request.execute(:method => :post,
        :url => 'http://api',
        :payload => payload)
    result.to_json
end

0 个答案:

没有答案