Alex
Alex

Reputation: 401

CasperJS upload image from url instead of server path

I'm using CasperJS to do my automation things. But for file uploading, I upload images from other website using exec() and wget to my server, then use CasperJS and casper.uploadFile() to post images on website.

Now I trying to post image using website image URL, I mean:

casper.then(function(){
    this.uploadFile("input[type='file']", '/var/tmp/img.jpg');
})

but I want to do:

casper.then(function(){
    this.uploadFile("input[type='file']", 'http://mywebsite.com/images/img.jpg');
})

and when I did that Casper just fails.

Upvotes: 1

Views: 122

Answers (1)

Rippo
Rippo

Reputation: 22424

Why not download the image first then upload it?

casper.then(function() {
  this.download("http://mywebsite.com/images/img.jpg", 'd:/_tmp/img.jpg');
}

casper.then(function(){
  this.uploadFile("input[type='file']", 'd:/_tmp/img.jpg');
})

See download from the docs

Upvotes: 1

Related Questions