Is There a way to view the uploaded pdf from CMS in the websie

I was creating a web app with CMS, and one of my fields is multi-document, which means the first user uploads the pdf file (data entry), then the second user must view, read, or download it (Management Level).

Is there a way to do it, aside from accessing the CMS table from the back end?

Hi there!

If you want administrators (management level users) to view the submitted user data on a secure page on the site, you should be able to access the pdf file outside of the CMS using the Wix Media Backend API.

Specifically, if you want to generate a link that allows users to download a file locally you can use the getDownloadUrl( ) method. This method provides a temporary URL for downloading a single file.

In order to use this method, you would need to query the CMS Collection where the user submissions are saved.

You will receive an array of objects where one value in each item represents the pdf file (document field) with a string value that is formatted in the following way:

wix:document://...

You can then use this string to get a temporary download URL for the user to load the file onto their local device.

Example (Backend Web Method for generating temporary media download URL):

import { Permissions, webMethod } from 'wix-web-module';
import { mediaManager } from 'wix-media-backend';

/* Sample fileUrl value: 'wix:image://v1/0abec0_51b1141c839c4d349035941cb9427ebe~mv2.jpg/child-on-bike.jpg#originWidth=768&originHeight=1024'
 * Sample expirationTime value: 10
 * Sample expiredTokenRedirectUrl value: 'https://www.my-redirect-url.com'
 */ 

export const myGetDownloadUrlFunction = webMethod(Permissions.Admin, async (fileUrl, expirationTime, downloadedFileName, expiredTokenRedirectUrl) => {
  const myFileDownloadUrl = await mediaManager.getDownloadUrl(fileUrl, expirationTime, null, expiredTokenRedirectUrl);  
  return myFileDownloadUrl;
});


/* Promise resolves to:
 * "https://download-files.wix.com/_api/download/file?downloadToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJpc3MiO..."
 */
1 Like

Can you help me to see how it looks like in the front end, when the temporary URL is assigned to a download button please?

Thank you.

The exact implementation depends on if the Button element is added on the page directly or in a repeater but generally you can use Button element’s onClick() event and the wixLocationFrontend.to() method to download the pdf using the temporary URL as a parameter.