MyBB Community Forums

Full Version: Imgur Upload
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8
(2013-08-19, 12:05 AM)martec Wrote: [ -> ]
(2013-08-18, 10:12 PM)Bitz Wrote: [ -> ]bump? :c

I can not help anything.
Works for me and I continue using in my forum.

which api key method did you use?
I think the old auth method has changed and the new api endpoint is different. Wish I knew JS.
(2013-08-21, 04:18 PM)Bitz Wrote: [ -> ]I think the old auth method has changed and the new api endpoint is different. Wish I knew JS.

for V3 API:

Change imgur.php to below:

<html>
<head>
<title>Upload to Imgur</title>
</head>
</html>
<div><img src="images/imgur.png" border="0" /></div>
<br /><br />
<button onclick="document.querySelector('input').click()">Select file...</button>
<input style="visibility: collapse; width: 0px;" type="file" onchange="upload(this.files[0])">

<script>
    window.ondragover = function(e) {e.preventDefault()}
    window.ondrop = function(e) {e.preventDefault(); upload(e.dataTransfer.files[0]); }
    function upload(file) {

        /* Is the file an image? */
        if (!file || !file.type.match(/image.*/)) return;

        /* It is! */
        document.body.className = "uploading";

        /* Lets build a FormData object*/
        var fd = new FormData(); // I wrote about it: https://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/
        fd.append("image", file); // Append the file
        var xhr = new XMLHttpRequest(); // Create the XHR (Cross-Domain XHR FTW!!!) Thank you sooooo much imgur.com
        xhr.open("POST", "https://api.imgur.com/3/image.json"); // Boooom!
        xhr.onload = function() {
            var code = '[img]' + JSON.parse(xhr.responseText).data.link + '[/img]';
            var editor = eval('opener.' + 'clickableEditor');
            editor.performInsert(code);
            javascript:window.close()
        }
        // Ok, I don't handle the errors. An exercice for the reader.
        xhr.setRequestHeader('Authorization', 'Client-ID <yourkey>');
        /* And now, we send the formdata */
        xhr.send(fd);
    }
</script>

<!-- Bla bla bla stuff ... -->

<style>
    body {text-align: center; background-color: #181817; overflow-x:hidden; overflow-y:auto;}
    div { background-color: rgb(43, 43, 43); border-bottom: 4px solid rgb(68, 68, 66); margin: -8px;}
	p {display: none}
    .uploading p {display: inline}
</style>
<br /><br />
<p><img src="images/loader.gif" border="0" /></p>

Based in http://stackoverflow.com/questions/16951...javascript
martec, does the key go inside the <> in this part of the code?

xhr.setRequestHeader('Authorization', 'Client-ID <yourkey>');
OK, I finally got it working.

Here's my revised code with out all of the HTML errors:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>Upload to Imgur</title>
</head>
<body>
<div>
<img src="images/imgur.png" border="0" /></div>

<button onclick="document.querySelector('input').click()">Select file...</button>
<input style="visibility: collapse; width: 0px;" type="file" onchange="upload(this.files[0])">

<script>
    window.ondragover = function(e) {e.preventDefault()}
    window.ondrop = function(e) {e.preventDefault(); upload(e.dataTransfer.files[0]); }
    function upload(file) {

        /* Is the file an image? */
        if (!file || !file.type.match(/image.*/)) return;

        /* It is! */
        document.body.className = "uploading";

        /* Lets build a FormData object*/
        var fd = new FormData(); // I wrote about it: https://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/
        fd.append("image", file); // Append the file
        var xhr = new XMLHttpRequest(); // Create the XHR (Cross-Domain XHR FTW!!!) Thank you sooooo much imgur.com
        xhr.open("POST", "https://api.imgur.com/3/image.json"); // Boooom!
        xhr.onload = function() {
            var code = '[img]' + JSON.parse(xhr.responseText).data.link + '[/img]';
            var editor = eval('opener.' + 'clickableEditor');
            editor.performInsert(code);
            javascript:window.close()
        }
        // Ok, I don't handle the errors. An exercice for the reader.
        xhr.setRequestHeader('Authorization', 'Client-ID 1234567890');
        /* And now, we send the formdata */
        xhr.send(fd);
    }
</script>

<span style="color:#fff;text-align:center;display:block;margin: 1em">Browse for your image, or drag and drop it into this window if you use FF or Chrome.</span>

<style>
    body {text-align: center; background-color: #000; overflow-x:hidden; overflow-y:auto; color:#888}
    div { background-color: rgb(43, 43, 43); border-bottom: 4px solid rgb(68, 68, 66); margin: -8px;}
    p {display: none}
    .uploading p {display: inline}
</style>

<p><img src="images/loader.gif" border="0" /></p> 
</body>
</html>
(2013-10-29, 07:43 PM)Shemo Wrote: [ -> ]martec, does the key go inside the <> in this part of the code?

xhr.setRequestHeader('Authorization', 'Client-ID <yourkey>');

in

<yourkey>

put Client ID key

result something this

xhr.setRequestHeader('Authorization', 'Client-ID 123456789');

123456789 = Client ID key

Client Secret it's not necessary...
(2013-10-30, 01:43 AM)martec Wrote: [ -> ]
(2013-10-29, 07:43 PM)Shemo Wrote: [ -> ]martec, does the key go inside the <> in this part of the code?

xhr.setRequestHeader('Authorization', 'Client-ID <yourkey>');

in

<yourkey>

put Client ID key

result something this

xhr.setRequestHeader('Authorization', 'Client-ID 123456789');

123456789 = Client ID key

Client Secret it's not necessary...

after switching to the new imgur.php and trying to upload a photo, when it places the [img] information in a post, this is how mine keeping showing up:

[img]undefined[/img]
Shemo,
That was my problem too, and I spent a lot of time figuring it out. Try my code in this post and let me know if that works. Remember to paste in your key.
http://community.mybb.com/thread-134658-...pid1045024


(2013-10-30, 08:13 PM)Shemo Wrote: [ -> ]
(2013-10-30, 01:43 AM)martec Wrote: [ -> ]
(2013-10-29, 07:43 PM)Shemo Wrote: [ -> ]martec, does the key go inside the <> in this part of the code?

xhr.setRequestHeader('Authorization', 'Client-ID <yourkey>');

in

<yourkey>

put Client ID key

result something this

xhr.setRequestHeader('Authorization', 'Client-ID 123456789');

123456789 = Client ID key

Client Secret it's not necessary...

after switching to the new imgur.php and trying to upload a photo, when it places the [img] information in a post, this is how mine keeping showing up:

[img]undefined[/img]
(2013-10-30, 08:22 PM)Monaco Wrote: [ -> ]Shemo,
That was my problem too, and I spent a lot of time figuring it out. Try my code in this post and let me know if that works. Remember to paste in your key.
http://community.mybb.com/thread-134658-...pid1045024


(2013-10-30, 08:13 PM)Shemo Wrote: [ -> ]
(2013-10-30, 01:43 AM)martec Wrote: [ -> ]
(2013-10-29, 07:43 PM)Shemo Wrote: [ -> ]martec, does the key go inside the <> in this part of the code?

xhr.setRequestHeader('Authorization', 'Client-ID <yourkey>');

in

<yourkey>

put Client ID key

result something this

xhr.setRequestHeader('Authorization', 'Client-ID 123456789');

123456789 = Client ID key

Client Secret it's not necessary...

after switching to the new imgur.php and trying to upload a photo, when it places the [img] information in a post, this is how mine keeping showing up:

[img]undefined[/img]

still shows undefined for me.
Guys, it first showed as undefined to, after some googling I found the fix.
Seems like a typo issue.

Just copy paste this one;

xhr.setRequestHeader('Authorization', 'Client-ID PUBLICKEYHERE);


I hope this helps!
Pages: 1 2 3 4 5 6 7 8