Question:
I need advice on how to rename a user uploaded file before I store it in Wix Media. The collection also needs to be updated with the file name and file url.
Product:
Wix Editor: Front End and Back End coding
What are you trying to achieve:
Here is the workflow that I am trying to implement on a Wix website.
- User uploads a file
- The file is validated
- The file name is “randomized”
- The file s uploaded to Wix
- Corresponding collection is updated.
What have you already tried:
I am new to Wix environment. I have written front end code to secure and validate the uploaded file for size (less than 5MB, only PDF is allowed, single file is allowed). On the backend, I wrote an “uploadFile” function where I tried the upload function. This seems to be the problem.
let uploadResult = await mediaManager.upload(folderPath, fileBuffer, newFileName, {
“mediaOptions”: { mediaType: “” },
});
Additional information:
It seems to me that upload function needs “buffer” as one of the inputs. Again, I am not sure how to create a buffer from a user file.