Jump to content

Fetch Images from Server Directory


Recommended Posts

I'm trying to convert: http://techslides.com/demos/image-video/create.html to work with images on a server.


Currently the demo above uses local files:

                if(filesarr.length>0){                    //loop through them and process                    for(i=0; i<filesarr.length; i++) {                        var file = filesarr[i];                        if(file.type.match(/image.*/)){                            process(file);                        } else {                            document.getElementById('status').innerHTML = "This file does not seem to be a image.";                        }                    }                } else {                    document.getElementById('status').innerHTML = "Please select some images.";                }

I'm trying to fetch them from a server, so I have replaced the above with:

				for(i=0; i < 2; i++) {									var url = "http://localhost/uploads/" + i.toString() + ".png";					var file = new Blob();								var xhr = new XMLHttpRequest();					xhr.open('GET', url, true);					xhr.responseType = 'blob';					xhr.onload = function(e) {										  if (this.status == 200) {						file = new Blob([this.response], {type: 'image/png'});						process(file);					  }					  					};					xhr.send();				}

Could someone tell me what I am doing wrong? I am not getting any errors so I have no idea.


EDIT: I feel very silly, there is nothing wrong with the above. I was still checking against the size of filesarr further down the script.

Edited by beennn
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...