0

I upload files to an S3 bucket using Javascript and want to verify, after the upload , that the file is where it should be.

Assuming I know the exact URL of the file (for example: https://mybucket.s3.amazon.com/myfile.png) is there a way for me to "ping" the file, just to make sure it is there?

Take into account this is cross domain as the JS may be running anywhere on the web, not just on my website.

Important notes:

  1. I can't simply load the image (if it is an image), because that will force the browser to download the whole file - I only want to "ping" it, to make sure it is there... not download a 5MB file, if you catch my drift.
  2. It isn't necessarily an image.

Thanks

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Che Kofif
  • 831
  • 1
  • 8
  • 22
  • You can get response headers see this question on how to do that http://stackoverflow.com/questions/220231/accessing-http-headers-in-javascript – Sandeep Manne Apr 03 '12 at 10:18
  • Sandeep - thanks, but I tried that already, it doesn't work because it is Cross Domain. I can't create an XMLHTTP object with a Get request to Amazon, as the script runs on various other locations, nor do I want to go through my own servers to do this- thats more server costs I cannot take. – Che Kofif Apr 03 '12 at 10:27

1 Answers1

-1
function ImgLoad(myobj,sSrc)
{
   var oImg=new Image;
   oImg.src="http://mydomain.com/images/"+sSrc;
   oImg.onload=function(){myobj.src=oImg.src}
   oImg.onerror=function(){alert("error");}
}
Dasarp
  • 194
  • 1
  • 5
  • Thanks but: Important notes: I can't simply load the image (if it is an image), because that will force the browser to download the whole file - I only want to "ping" it, to make sure it is there... not download a 5MB file, if you catch my drift. It isn't necessarily an image. – Che Kofif Apr 03 '12 at 10:01
  • just put a return false in onload event... if you don't want to load the picture... you'll probably know files is there in first occurance of the onload function – Dasarp Apr 03 '12 at 10:08
  • Hmm.. interesting, I'll try that and get back to you. Though that won't work for a non image file presumably, anyway). – Che Kofif Apr 03 '12 at 10:14
  • I'm afraid that didn't solve it - it doesn't cancel the download of the image. – Che Kofif Apr 03 '12 at 10:22
  • return false works... or you may unbind the onload event or set it to null... for your reference... http://jsfiddle.net/nick_craver/gjH6E/ – Dasarp Apr 03 '12 at 10:28
  • I think you may have misunderstood the issue - the moment the image is given the source of the file on the server it starts downloading it - I want to abort the download, because I don't want to download the file (it can be several MBs), I just want to check that it is there. In your example it continues to download the image... – Che Kofif Apr 03 '12 at 10:47