Is it possible to upload a jpeg file from a directory on my web server via Ajax? Currently the call that is created is receiving the jpeg from a form file upload using FormData(); .append('file', $('#imageFile')[0].files[0]);
I have the file on the server and would like to call that Ajax function via document ready or onLoad to prevent an extra step.
Here my current function:
function uploadImage() {
var formData = new FormData();
formData.append('file', $('#imageFile')[0].files[0]);
$.ajax({
url: 'http://api.abcbiz.com/v1/graphics',
headers: { Accept: 'application/json' },
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false,
success: function(data) {
var zpl = $('#zpl').val();
var index = zpl.toUpperCase().indexOf('^XA');
var cmd =
'\n'
+ '\n'
+ '^FO20,10^GFA,' + data.totalBytes + ',' + data.totalBytes + ',' + data.rowBytes + ',' + data.data + '^FS\n'
+ '\n'
+ '\n';
if (index == -1) {
zpl = cmd + zpl;
} else {
zpl = zpl.substring(0, index + 3) + cmd + zpl.substring(index + 3);
}
$('#sendZPL').val(zpl);
$('#hiddenForm').stop(true,true).slideToggle(500);
$('#zpl').val(zpl);
refreshLabel();
refreshPermalink();
},
error: function(jqxhr) {
alert(jqxhr.responseText);
}
});
}
I also tried using cURL via PHP to bypass using the Ajax call but I kept getting a 'Unknown File Type" from the receiving server.
I appreciate any ideas. Thanks.