'How to get Vimeo Uploaded VideoID after uploading it
I am using Vimeo and tus. I want to upload videos to Vimeo(React frontend) and then display Vimeo embed to the user as a preview But in the Vimeo response, I am not getting a video id or any kind of preview URL
Code
const headerPost = {
Accept: 'application/vnd.vimeo.*+json;version=3.4',
Authorization: `bearer ${process.env.REACT_APP_VIMEO_ACCESS_TOKEN}`,
'Content-Type': 'application/json',
};
export const uploadFile = async ({ file, onSuccess, onError, onProgress }) => {
const fileName = file.name;
const fileSize = file.size.toString();
const response = await axios({
method: 'post',
url: `https://api.vimeo.com/me/videos`,
headers: headerPost,
data: {
upload: {
approach: 'tus',
size: fileSize,
},
},
});
// Create a new tus upload
const upload = new Upload(file, {
endPoint: 'https://api.vimeo.com/me/videos',
uploadUrl: response.data.upload.upload_link,
retryDelays: [0, 3000, 5000, 10000, 20000],
metadata: {
filename: file.name,
filetype: file.type,
},
headers: {},
onError: function (error) {
console.log('Failed because: ' + error);
onError(error);
},
onProgress: function (bytesUploaded, bytesTotal) {
let percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2);
console.log(bytesUploaded, bytesTotal, percentage + '%');
onProgress(percentage);
},
onSuccess: function async() {
console.log('Download ', upload, upload.url);
onSuccess(upload);
},
});
// Start the upload
upload.start();
};
upload Object : Link
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
