I am implementing uploading images, photos using the imgur
.
So far I have developed the dropzone option, which allows me to drag or click the Dropzone to upload/upload images and save them to imgur
and not my local hosting.
Through my upload.js code.
var feedback = function(res) {
if (res.success === true) {
var get_link = res.data.link.replace(/^http:\/\//i, 'https://');
document.querySelector('.status').classList.add('bg-success');
document.querySelector('.status').innerHTML =
'Image : ' + '<br><input class="image-url" value=\"' + get_link + '\"/>' + '<img class="img" alt="Imgur-Upload" src=\"' + get_link + '\"/>';
}
};
new Imgur({
clientid: '', //You can change this ClientID
callback: feedback
});
And from a simple structure of HTML
.
<body>
<div class="title">
<h1>Imgur Upload API</h1>
<p>Use JavaScript To Upload Image</p>
</div>
<div class="dropzone">
<div class="info"></div>
</div>
<script type="text/javascript" src="./js/imgur.js"></script>
<script type="text/javascript" src="./js/upload.js"></script>
</body>
I get my dropzone
that allows me to upload/upload the images to hosting imgur
.
I have added the following lines to the imgur.jsfd.append('type', 'URL');
code .
var fd = new FormData();
fd.append('image', file);
fd.append('type', 'URL');
But how can you add the option to enter an image url and upload/upload save to imgur?
I want to add both options in my dropzone, upload images locally and use an image url.
The same StackOverflow system, which allows drag image/select image and at the same time allows uploading images from an example image URL:
I've had a look at your question and at the imgur library .
On the one hand, indicate that this library is available on github . Perhaps you should consider contributing to the project, creating your own variant, or contacting its author to include this new feature.
On the other hand, and without modifying the current library of a third party, you can use this little 'hack' to achieve your goal.
Simply, it is about using the POST method of the imgur library using any given url as image value.
You can see a working example in the following code implementing a submission form outside the dropzone provided by the library.