I want to do background uploading with web worker in my ember octane app as we upload very large assets so i have a method inside class as following
export default class UtilsUploadComponent extends Component {
private asyncUpload() {
var worker_fn = () =>
{
let data = yield this.sendData(file) // i want to achieve that
self.postMessage(data);
};
var blob = new Blob(["onmessage ="+worker_fn.toString()], { type: "text/javascript" });
var worker = new Worker(window.URL.createObjectURL(blob));
worker.onmessage = function(e)
{
console.log(e.data);
};
worker.postMessage("start");
return -1
}
async sendData(file: File, url) {
let formData = new FormData();
formData.append('data', file, file.name);
const response = await this.apiRequest.POST(url, formData);
return response.json()
}
}
so i want to call send data inside worker function and call post message after i received the data ?
Aucun commentaire:
Enregistrer un commentaire