dempsey
dempsey

Reputation: 1

How to private image/video with CDN address

I have a springboot project and use huawei's cloud to store pictures and videos. The problem is how can I prevent other people from seeing the photos/videos when they have a CDN address that I have not allowed.

I tried to find out, I know the cloud server side can solve this problem

But I want to know if there is a way to handle it on the code side, if so, how? Please let me know if you have the answer.

Sorry I am not allowed to show the project code.

Thanks!!

Upvotes: 0

Views: 124

Answers (1)

cakepbm
cakepbm

Reputation: 66

Here is a way but it is impossible to guarantee 100% that photos/videos won't be leaked if another user gets the URL. The solution is to use signed URLs with a validity period. legal users can still get a regenerated signed URL even after the original one has expired.

import com.obs.services.ObsClient;
import com.obs.services.model.TemporarySignatureRequest;
import com.obs.services.model.TemporarySignatureResponse;

ObsClient obsClient = new ObsClient("access key", "secret key", "obs endpoint");

// Create a request for a temporary signed URL
TemporarySignatureRequest request = new TemporarySignatureRequest();
request.setMethod("GET");
request.setBucketName("bucket name");
request.setObjectName("object name");
request.setExpires(3600);  // Set URL to expire after 1 hour

// Get the temporary signed URL
TemporarySignatureResponse response = obsClient.createTemporarySignature(request);
String signedUrl = response.getSignedUrl();

You can shorten the expires to increase security . but nothing is completely secure.

Upvotes: 0

Related Questions