I have used some code from within the forum that allows a user to upload a file to MediaManager.
https://www.wix.com/velo/forum/tips-tutorials-examples/upload-import-csv-file-to-content-manager-from-page-frontend
export function submit_click(event) {
console.log('click')
$w("#submit").disable();
$w("#uploadButton1").startUpload()
.then((res) => {
console.log(res)
let file = res.url;
let data = {
title: 'My file',
file: file,
mediaId: res.mediaId
};
wixData.insert('Uploadedcsv', data)
.then((result) => {
$w("#submit").enable();
});
});
}
I then have some backend code that in theory uses the fetch method to get the file information as text. https://www.wix.com/velo/forum/coding-with-velo/access-user-uploaded-files-from-backend-1
export async function check() {
console.log("Start Check");
let user = wixUsersBackend.currentUser;
let data = await wixData.query("Uploadedcsv").eq("_owner", user.id).limit(1).find();
for (let i = 0; i < data["length"]; i++) {
let wix_filename = data["items"][i].file;
let url = await mediaManager.getFileUrl(wix_filename)
console.log(url)
let file = await fetch(url);
console.log(file)
let content = await file.text()
console.log(content)
}
}
Unfortunately, whilst i do get results in the console.log(file) of status 200, headers, body ect the console.log(content) is undefined. Can anyone help so i can read the content of the CSV file all be it as text?
Sorry all my mistake, missed an await on the file.text().