How to send Windows Azure Storage blob to browser

2019-07-27 10:54发布

Situation: I have a large set of videos and images and small Play applications, which stores references to the blobs in DB. For web usage that's OK, I'm rendering page, where I put Flowplayer and in it's config I'm using direct blob's path as a source video. Anyway I was asked for additional possibility for other older devices - which should send the file in the response body directly with headers:

Content-Type:video/mp4
Content-disposition:inline
Content-Transfer-Encoding:binary

Originally that solution was done with PHP script, which fetched the blob to the server with the CURL and returned as a response to the client with manipulated header.

Question: What is the best way to do that job with Play? (preferably without downloading file to the server). Blobs will be public, so I don't need to care about hiding original paths, I just need to add headers mentioned above.

  1. Should I use WS.url() to fetch the file to the server and send it as a Result with modified headers? I tried this, but had some problems with WS timeouts.
  2. Also tried to set the header Content-Location:http//mystorage..., anyway as I understood it requires file in the response body anyway. So maybe there is some other technique with usage of the headers only.
  3. Is there any way to force custom headers while returning direct blob (ie. by setting it in the GET params) ?

Maybe some quite other approach?

1条回答
唯我独甜
2楼-- · 2019-07-27 11:29

I solved my problem with approach no. 1, but with usage of java.net.URL instead of WS.url(),

Bounty promise is actual for better propositions (especially, if it will be done without downloading file to the server).

查看更多
登录 后发表回答