28 lines
699 B
JavaScript
28 lines
699 B
JavaScript
|
importScripts('formdata.js')
|
||
|
|
||
|
self.onmessage = function(event) {
|
||
|
var data = JSON.parse(event.data);
|
||
|
|
||
|
var request = new XMLHttpRequest();
|
||
|
request.open('GET', data.url, true);
|
||
|
request.responseType = 'arraybuffer';
|
||
|
request.onload = function(e) {
|
||
|
if (request.status == 200) {
|
||
|
uploadBuffer(data.pomfclone, request.response, data.filename);
|
||
|
}
|
||
|
};
|
||
|
request.send();
|
||
|
};
|
||
|
|
||
|
function uploadBuffer(pomfclone, buffer, filename) {
|
||
|
var formData = new FormData();
|
||
|
formData.append('files[]', buffer, filename);
|
||
|
|
||
|
var request = new XMLHttpRequest();
|
||
|
request.open('POST', pomfclone + '/upload.php', true);
|
||
|
request.onload = function(e) {
|
||
|
postMessage(request.response);
|
||
|
};
|
||
|
request.send(formData);
|
||
|
};
|