在Javascript中将图像转换为二进制数据或字符串 [英] Convert Image to Binary Data or String in Javascript
问题描述
我正在使用Chrome扩展程序上的XMLHttp请求将图像文件上传到TWITPIC。我需要发送图像作为有效载荷。有没有办法做到这一点 ?我发现此链接将图像转换为JavaScript中的二进制数据
但是这对图像标签有效。我需要一种方法来指定图像文件路径并将图像上传到TWITPIC。
我开始通过HTML 5了解FileReader API。有什么方法可以使用它?它应该在本地文件上工作。
Chrome扩展程序是否支持FileReader API而不运行本地主机服务器?
我自己找到了答案。 Chrome扩展确实支持HTML5的FileReader API。所以,下面的代码工作起来很简单。
var reader = new FileReader();
reader.readAsDataURL(f);
I am working on uploading image file to TWITPIC using XMLHttp Request on a Chrome Extension . I need to send the image as payload. Is there a way to do this ? I found this link Convert an image into binary data in javascript But that works on image tags. i need a way to specify image file path and upload image to TWITPIC.
I came to know about FileReader API with HTML 5. Is there any way to work using that??. It should work on a local file.
Does Chrome Extension support FileReader API without running a localhost server ??
I found the answer myself. Chrome Extensions does support FileReader API of HTML 5. So just the code below works simple.
var reader = new FileReader();
reader.readAsDataURL(f);
这篇关于在Javascript中将图像转换为二进制数据或字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!