Reputation: 1
The following code is a part of a web file search engine (.stl files) that takes file found by the search engine and automatically finds a file input on the webpage where it procceeds to upload it there. It works perfectly on desktop (chrome browser at least) but fails to work on mobile, got any proccesses or ideas that might get it to work?
async function uploadFile(downloadUrl, fileName) {
const apiKey = 'Insert API Key';
try {
const response = await fetch(downloadUrl, {
headers: {
'Authorization': `Bearer ${apiKey}`
}
});
const blob = await response.blob();
const fileInputs = document.querySelectorAll('input[type="file"]');
fileInputs.forEach(fileInput => {
const dt = new DataTransfer();
dt.items.add(new File([blob], fileName));
fileInput.files = dt.files;
const event = new Event('change', { bubbles: true });
fileInput.dispatchEvent(event);
});
// Scroll the page down by 40%
window.scrollTo(0, document.body.scrollHeight * 0.4);
// Prevent file directories from popping up
preventFileDialog();
} catch (error) {
console.error('Error uploading file:', error);
}
}
Tried using session storage rather tha local storage I think, not actually sure if those are different things.
Upvotes: 0
Views: 26