开发者

Write non ASCII char with PhoneGap Javascript Image

Here is what I'm doing : In javascript I ask for an image with AJAX. The server php execute the following code :

readfile($pa开发者_开发知识库thfile);

Then the javascript receive the data, and with Phonegap I try to write it to a file :

var writer = new FileWriter();
writer.fileName = "./../Documents/" + nameFile;
writer.write(dataReceived);

In fact, it works with ASCII chars, but the function "write" fail with the content of the image received (png format). So I tried to encode the transferred data in Base64, in Hexadécimal and it works. But I don't want to store encoded data because I want to use it later in "img" tags (html tag). And make something like :

<img src='./../Documents/createdFile.png' />

Do you have any idea on how to write any characters in Phonegap to a file? Or what I'm doing wrong with the FileWriter of PhoneGap ? I know the way to do something like src='Image.php', but I have to store files on the device.

I've got the version 0.9x of Phonegap (included with Dreamweaver). Thanks in advance.


I finally found the explication. To begin I want to say that I just learned javascript ;) .So I asked the question to "macdonst" on github and he answered me :

"Sadly, you will be unable to write binary data with the FileWriter. JavaScript can't handle binary data very well and we can't pass binary data from the JavaScript side to the Native side so it is a limitation we have to live with.

However, once you've written you've gotten your base64 image data you can display it like this:

<img src="data:image/gif;base64,{this is where your base64 data goes}" />

"

Thanks to "macdonst", I posted his answer because I hope it will help beginners like me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜