I need to upload an external image file to a WIX collection through a C# program using the POST http function. Unfortunately, I have not found a suitable post in the forum. Is there a detailed WIX API instruction for this use case?
Thanks!
I need to upload an external image file to a WIX collection through a C# program using the POST http function. Unfortunately, I have not found a suitable post in the forum. Is there a detailed WIX API instruction for this use case?
Thanks!
Hi Affolter ![]()
Yes, you can use the upload() function in your endpoint function, just include the URL of the file with your post request.
First you’ll need to add the request-promise npm package.
import { mediaManager } from 'wix-media-backend';
import rp from 'request-promise'; // npm package
let endpointResponse; // The response from your 3rd party server.
const fileUrl = endpointResponse.url // The file URL
const fileName = endpointResponse.fileName; // myVideo.mp4
// Generate a buffer
return rp.get({ fileUrl, encoding: null }).then((Buffer) => {
const folderPath = '/uploads/external';
// Srart uploading the file.
return mediaManager.upload(folderPath, Buffer, fileName).then((uploadedFile) => {
// This is the URL of the file hosted on Wix
const finalUrl = uploadedFile.fileUrl;
})
})
PLEASE NOTE:
You can only upload specific file types and sizes, click here to learn more.
You can determain if the finalUrl is public or not by passing a metadata options parameter, the url is “Public” by default.
If the finalUrl’s isPrivate metadata was set to true, you can only download the file by generating a temporarily link.
Hope this helps~!
Ahmad
Hi Ahmad,
Thanks for your quick answer.
Krgds
Sascha
@affoltes You’re welcome ![]()