I'm working on a piece of code using the Stripe Connect API where the user can send a visual from an input type="file" to an AJAX call via jQuery, this way:
var form_file = new FormData();
form_file.append('file', document.querySelector('input#file_to_send').files[0]);
When the user submits the form, I copy the visual in a folder on my server via PHP and keep its name in a session variable.
If something is incorrect or missing in the form, the user goes back to the same page, where the visual is shown in a img element under the input type="file" one, so the user knows that their visual has been taken into consideration.
After that, I need to do send the file in an AJAX call again... Except that this time, the file cannot be selected from the input type="file" anymore, the only accessible source I have would be to take it's name from the img element in JavaScript.
Now, if I do this:
var form_file = new FormData();
form_file.append('file', $('img#visual').attr('src'));
And send this via the same AJAX call:
$.ajax({
    url: 'https://uploads.stripe.com/v1/files',
    type: 'POST',
    processData: false,
    contentType: false,
    headers: {'Authorization': 'Bearer xxxxxxxxxxxxxxxxx' },
    data: form_file
}).fail(function(e) {
    console.log('fail: ' + e);
}).done(function(e) {
    console.log('file uploaded: ' + e.id);
});
My question, you guessed it, is: is there a way to/how should I do to send a file not from an input element as a source, but a defined path taken from an img element?
 
     
     
    