0

I've been looking at similar questions on here and done lots of Googling but nothing is exactly correct to how I need it.

I need to have a script that when the javascript is called, it will take you to a direct jpg location on the web server and POST it to an external server. I have the servers POST receiving files fine and I actually have some code that POSTs a variable okay. I just really need the image 'get' The example:

  1. User goes to page with javascript included
  2. script grabs jpg from set location E.G /img/coolphoto.jpg
  3. Post image to external server

I've played with XMLHTTPRequest to get the jpg, but I am not having great luck. I've tried converting to BASE64 and all sorts, but I guess I am doing things slightly wrong.

Could anyone give a hand? Thanks

UPDATE:

function httpGet(theUrl)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
    xmlHttp.send( null );
    return xmlHttp.responseText;
}

So this is the code I am using to grab the image, I really just need this to grab it, base64 it so I can POST the BASE64 to my server, and then decode on the server to get the jpg

MrTurvey
  • 23
  • 3
  • Start by showing some code ;) So it will be more clear what needs to be done – sietse85 Aug 05 '16 at 12:56
  • @sietse85 I added the code which I am using to get the Image :) – MrTurvey Aug 05 '16 at 13:02
  • I have found an almost similiar question which hopefully can get you a little bit further http://stackoverflow.com/questions/8778863/downloading-an-image-using-xmlhttprequest-in-a-userscript the answer there contains a lot of usefull stuff you could use in your script – sietse85 Aug 05 '16 at 13:06

0 Answers0