Pergunta

I am making a Google chrome extension but I guess this is more a general Javascript question.

I want to upload a image from its URL to a hosting website.

Does any hosting website provides such an api?


Detail of the process:

  1. The user copy a image URL
  2. The chrome extension would send the image to a image hosting website
  3. The extension gets a callback with the link of the image saved on the hosting website
Foi útil?

Solução

Wow I just found Imageshack and it just does what I need. The API is very simple! Here is a working example:

First login with your username and password to get an access token

var token = "";

$.ajax({
  type: "POST",
  url: "https://api.imageshack.com/v2/user/login",
  data: { api_key: "*****************", user: "**********", password: "*******" }
})
  .done(function( msg ) {
    token = msg.result.auth_token;
  });

Once you got this token, you can upload an image from a URL.

 var imgUrl = "http://www.scarlettjohansson.org/hairstyles/scarlett-johansson-hairstyle-3.jpg";

 $.ajax({
  type: "POST",
  url: "https://api.imageshack.com/v2/images",
  data: { api_key: "2579FJLP41717571ea15b5405adcbac60bf1dc44", auth_token: token, urls: [imgUrl]}
 })
   .done(function( msg ) {
     console.log( msg );
  });

This only has a 30days free trial. If someone has a free alternative it would be great!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top