Code: Select all
function getFileSize(url)
{
var fileSize = '';
var http = new XMLHttpRequest();
http.open('HEAD', url, false); // false = Synchronous
http.send(null); // it will stop here until this http request is complete
// when we are here, we already have a response, b/c we used Synchronous XHR
if (http.status === 200) {
fileSize = http.getResponseHeader('content-length');
console.log('fileSize = ' + fileSize);
}
return fileSize;
}
The reason I am trying to do this is to compare the file before downloading to the downloaded file. What is happening is that I am using cURL to download the file and before it finishes downloading Photoshop places it into my document. This leads to a black block of missing data in the image.
Code: Select all
app.system("curl -o ~/Desktop/jpegs/Download_Folder/" + skuNumber + ".jpeg https://mysite.com/image/" + skuNumber + ".fpx?qlt=100&printres=300&fmt=jpeg")
This is all fine except if there is a lag spike and the file size doesn't grow, it breaks out and places an incomplete image file in my document.
So, my thought is, if I can get the size of the original file in bits and check the downloaded file against it, it solves a lot of problems.
Any thoughts?
Thanks,
Paul