如何将imgur HTML5上传器添加到网站 [英] How to add imgur HTML5 uploader to website

查看:96
本文介绍了如何将imgur HTML5上传器添加到网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在尝试将imgur上传器小部件放到我的网站中

我在这里看到了一些代码: http://api.imgur.com/examples

Hello,

I''m trying to get the imgur uploader widget into my site

I saw some codes here: http://api.imgur.com/examples and got my API code and this is the html5 code:

// trigger me onclick
function share(){
    try {
        var img = canvas.toDataURL('image/jpeg', 0.9).split(',')[1];
    } catch(e) {
        var img = canvas.toDataURL().split(',')[1];
    }
    // open the popup in the click handler so it will not be blocked
    var w = window.open();
    w.document.write('Uploading...');
    // upload to imgur using jquery/CORS
    // https://developer.mozilla.org/En/HTTP_access_control
    $.ajax({
        url: 'http://api.imgur.com/2/upload.json',
        type: 'POST',
        data: {
            type: 'base64',
            // get your key here, quick and fast http://imgur.com/register/api_anon
            key: 'YOUR-API-KEY',
            name: 'neon.jpg',
            title: 'test title',
            caption: 'test caption',
            image: img
        },
        dataType: 'json'
    }).success(function(data) {
        w.location.href = data['upload']['links']['imgur_page'];
    }).error(function() {
        alert('Could not reach api.imgur.com. Sorry :(');
        w.close();
    });
}


但是后来我发现我什至不知道如何使用它!

任何人都可以提供一个简单的代码/示例,以说明如何使此代码成为HTML上载器,其中将带有一些选择按钮并进行上载,而上载器之类的东西可能具有该功能?
谢谢:D


But then I discovered I don''t even know how to use it!

Can anyone please supply a simple code/example on how can I make this code an HTML uploader where it will have some choose button and upload and stuff like uploader may have?

Thank you :D

推荐答案

.ajax({ 网址:' http://api.imgur.com/2/upload.json', 类型:' POST', 数据: { 类型:' base64'// 在这里快速快捷地获取密钥http://imgur.com/register/api_anon 键:' 您的API密钥', 名称:' neon.jpg', 标题:' 测试标题', 字幕:' 测试字幕', 图片:img }, dataType:' json' }).success(函数(数据){ w.location.href = data [' upload'] [' 链接'] [' imgur_page ']; }).error(function(){ alert(' 无法访问api.imgur.com.抱歉:('); w.close(); }); }
.ajax({ url: 'http://api.imgur.com/2/upload.json', type: 'POST', data: { type: 'base64', // get your key here, quick and fast http://imgur.com/register/api_anon key: 'YOUR-API-KEY', name: 'neon.jpg', title: 'test title', caption: 'test caption', image: img }, dataType: 'json' }).success(function(data) { w.location.href = data['upload']['links']['imgur_page']; }).error(function() { alert('Could not reach api.imgur.com. Sorry :('); w.close(); }); }


但是后来我发现我什至不知道如何使用它!

任何人都可以提供一个简单的代码/示例,以说明如何使此代码成为HTML上载器,其中将带有一些选择按钮并进行上载,而上载器之类的东西可能具有该功能?
谢谢:D


But then I discovered I don''t even know how to use it!

Can anyone please supply a simple code/example on how can I make this code an HTML uploader where it will have some choose button and upload and stuff like uploader may have?

Thank you :D


这篇关于如何将imgur HTML5上传器添加到网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆