UPLOAD IMAGE DISPLAY CODE

EMANUEL B.
05 Jun 2018, 06:51

HI,
I'm triyng to insert upload string.
Player choose image by his computer

show your image

but the image won't display.

CAN U HELP ME?
Thanx


mrangel
05 Jun 2018, 07:44

I assume you're uploading the image to some external site?

This is likely to be hard to get working. If you have some code already, you could show us and see if anyone can sot what's wrong with it.


EMANUEL B.
06 Jun 2018, 06:49

Yes,the player choose the image by his pc.
On Quest doesn't work.

This is the code:


EMANUEL B.
06 Jun 2018, 07:02

This is the code:

<input type="file" accept="image/*" onchange="loadFile(event)">
<img id="output"/>
<script>	
  var loadFile = function(event) {
    var output = document.getElementById('output');
    output.src = URL.createObjectURL(event.target.files[0]);
        };
 </script>

K.V.
06 Jun 2018, 07:53

Do it like this:

<input type="file" accept="image/*" onchange="loadFile(event)"/>
<img id="output"/>
<script> var loadFile = function(event) {    var output = document.getElementById('output');    output.src = URL.createObjectURL(event.target.files[0]);        }; </script>

image


EMANUEL B.
06 Jun 2018, 08:05

Thanks a lot.
U'RE THE BEST.
Wonderful


K.V.
06 Jun 2018, 08:09

No problem!

Quest adds a <br/> in the code for every line break.

So it was turning your script into this behind the scenes:

<script> <br/> var loadFile = function(event) {<br/> var output = document.getElementById('output');<br/> output.src = URL.createObjectURL(event.target.files[0]);<br/> }; <br/></script>


K.V.
06 Jun 2018, 08:12

PS

I totally stole your code and put it on my Wiki. (I did mention you, though.)

https://github.com/KVonGit/QuestStuff/wiki/Import-an-Image-Using-HTML-and-JS


K.V.
06 Jun 2018, 08:21

PPS

If you add this to the end of the script, you can save the data as a variable to print the image whenever you like (as long as the game isn't exited and loaded from a saved game):

uploadedImg = output.src;

To use that:

JS.eval("addTextAndScroll (\"<img src='\"+uploadedImg+\"'>\");")