How to get a file content in Wix?

I have an “uploadButton” on my site, but it only allows to upload directly to the wix media manager. I want access to the file content in my code to upload it to AWS S3.

Is there any way with Wix to get a file content from the user in the code?

Thanks

In this case you will first need to upload the file on the Wix Media Manager then get the public URL for the file which you can then upload to your AWS S3 bucket.

You will need to use something like Node Fetch or Wix Fetch itself to create a buffer from the URL and then upload it to S3 using the following parameters

var params = {
     Bucket: bucket_name,
     Body: buffer, //
     Key: `images/wix_image02.png` //path and file name
};

Thanks for the answer.
I’m trying to do it but there are 2 things -

  1. how do i get the public url? the url i’m getting is “wix:/video://v1/…”

  2. is there a way to delete the file from the file manager from the code?

Thanks!

@magenheim The startUpload() function gives you a **mediaId** - use that to call Wix Media Backend’s getFileUrl() function which will give you a public link to that file.

Currently you cannot delete the file from the Wix Media Manager with code, its a requested feature so please vote for it if you want to see Wix develop it faster.

@shantanukumar847 .
First of all thanks again for all the help.

I managed to make it work, but it seems that wix-fetch is corrupting the data in the process.

this is the code I’m using -

mediaManager.getFileUrl(uploadedFile.mediaId)
  .then(function(filePublicUrl) 
  {
    fetch(filePublicUrl, {"method": "get"})
    .then((httpResponse) => httpResponse.text())
    .then(
 function(data) 
      {
 var upload = new AWS.S3.ManagedUpload({
          params: {
            Bucket: bucketName,
            Key: videoKey,
            Body: new Buffer(data, 'binary') 
          }
        });
 var promise = upload.promise();
        promise.then()
      });
  });

any idea why the file is uploaded corrupted?