简体   繁体   English

从url获取图像并使用javascript转换为blob

[英]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: 我有一个带有这样图像的URL:

http://maps.google.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&sensor=false 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. 我需要使用ajax或其他工具加载此图像,然后将其转换为blob以保存在我的数据库中。

Thanks 谢谢

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. 将图像blit到canvas元素,从画布生成动态URI,将URI解码为字节,构造blob,添加到FormData对象,并使用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. PS - 因为图像是由Google提供的,所以您需要使用代理来规避“同源”安全策略,如我的链接帖子中所述。

That is against the Terms of Use . 这违反了使用条款

See this FAQ which addresses your question. 请参阅此常见问题解答以解决您的问

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM