So a user may upload a text file from my website but how do I count the number of lines in the text document (and impose a maximum limit on the number of lines uploaded) please?
You can easily limit file upload by number of bytes . but you wanted to limit by number of lines (btw, line can be long or short? So what’s the point) –
So:
If you use Velo only (and don’t want to write some complicated code in custom element), the way to do it is to let the user upload the file, read it (see below), and then if there’re more than X lines, show a rejection message (but the file will be on the servers until you manually delete it).
try something like:
First write a function to upload the file once the uploadButton value has changed.
Then convert the Wix file uri into an http url.
then use fetch(url) to get the file, then response.text(), then result.split(‘\n’).length should be the number of lines.
J.D.
thank you for your helpful reply. I have now coded such an approach which works well.
I am new to velo and javascript and find it very difficult to “hack” the code compared to other languages such as php.
It is a shame that oversized uploads have to be deleted manually as I like to automate everything.
FYI users are uploading urls and they are limited to how many they are allowed to upload.
Thank you again
Maybe in the future Velo API will support removing files completely.
But currently you can still move the file to trash by code (you just cannot empty the trash by code).
to move it to trash, create a js w on the backend, put there an export function:
//backend/media.jsw
import {mediaManager} from 'wix-media-backend';
export const moveToTrash = (fileUrls) => mediaManager.moveFilesToTrash(fileUrls);
//front-end:
import {moveToTrash} from 'backend/media.jsw';
//when you want to move to trash
return moveToTrash([url]);
J.D. that is really helpful re trash thank you again