Answer the question
In order to leave comments, you need to log in
How to make a temporary link?
Good evening, is it possible somehow to make a temporary link from a remote link.
Let's say there is a file remote.server/test.img
Make this link something like domain.ru/asd76HJGgh.jpg
Is it possible to implement this using express?
Answer the question
In order to leave comments, you need to log in
Yes, it is quite.
To do this, you need to:
1. Create a table in the database (or a file) to store temporary links: correspondence of abracadabra and a file name on disk or a link to a file on the Internet, link lifetime, access rights, etc.
2. Create a router in express, for example:
...
app.use('/temp/:id', function(req, res, next){
// console.log('ID:', req.params.id);
// тут абракадабра лежит в req.params.id
// далее вы достаете из БД данные о
// полученом ID проверяете срок жизни
// права доступа и отдаете локальный файл
// res.sendFile('/путь/до/файла/имяфайла');
// либо делаете редирект на удаленный файл
// res.redirect('remote.server/test.img');
// или сообщаем о причинах отказа
// доступа к этому файлу
// res.send('Вы не правы:)');
}
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question