N
N
nezzard2018-10-16 22:05:44
Node.js
nezzard, 2018-10-16 22:05:44

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

1 answer(s)
R
Roman, 2018-10-16
@nezzard

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('Вы не правы:)');
}
...

PROFIT.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question