Cloudinary signed Uploads not found when signing again in back end
Unanswered
Narrow-barred Spanish mackerel posted this in #help-forum
Narrow-barred Spanish mackerelOP
Hi, I'm using cloudinary for hosting videos, and i want to create temporary links as a way to protect the videos that are hosted. I sign the upload on the front end, using cloudinary's upload widget and a route. This returns a signed URL that works fine, but i want to add a time restriction and deliver the video to the user through that link, but when i try to sign the url with the restriction on the backend, an error shows up saying that the resourse wasn't found, when I try to access the new link. I'm using next-cloudinary.
this is my backend controller
this is my backend controller
require("dotenv").config();
const cloudinary = require("../../utils/cloudinary");
const { CLOUDINARY_API_SECRET } = process.env;
const Videos = require("../../models/Videos");
async function getVideoById(req, res, next) {
try {
const { id } = req.params;
const video = await Videos.findById(id);
if (!video) res.status(404).json({ message: "Video no encontrado" });
// Genera una firma con una validez de 60 segundos
const currentTimeInUTC = Math.round(Date.now() / 1000);
const expiresAt = currentTimeInUTC + 60;
const signature = cloudinary.utils.api_sign_request(
`${expiresAt}`,
CLOUDINARY_API_SECRET
);
console.log('signature' , signature);
// Usa private_download_url para generar la URL privada
const secureVideo = cloudinary.utils.private_download_url(video.id, "mp4", {
expires_at: expiresAt,
signature: signature
});
return res.status(200).json({ url: secureVideo });
} catch (error) {
next({ message: error.message, statusCode: 404 });
}
}
module.exports = getVideoById;