Franz Torrez
Franz Torrez

Reputation: 49

Get image from url and convert into blob using javascript

Well guys i was looking many hours for internet and i couldn't find the answer.

I have an URL with an image like this:

http://maps.google.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&sensor=false

I need to load this image using ajax or another tool and later convert it into a blob to save in my database.

Thanks

Upvotes: 1

Views: 7610

Answers (2)

Joe Coder
Joe Coder

Reputation: 4525

Blit the image into a canvas element, generate a dynamic URI from the canvas, decode the URI into bytes, construct a blob, add to a FormData object, and submit with XMLHttpRequest.

See here.

PS - because the image is served from Google, you will need to use a proxy to circumvent "same-origin" security policy, as described in my linked post.

Upvotes: 2

geocodezip
geocodezip

Reputation: 161334

That is against the Terms of Use.

See this FAQ which addresses your question.

Upvotes: 1

Related Questions