- Home /
How To Know File Changed
Hi. i Wanted To Get one image From Server(Offline game) And Keep For Loading Offline. But I'm Changing That Image Time to Time So I Want To Know Image Changed To Download It Again. Ho To Know the Image Changed Or Not? Also I'm Using WWW to Get Image
the simplest solution I can think of is to have an extra file on both the server and locally that contains images versions. For example, on the server it could be something like:
Player_texture:4
Tree_texture:2
and on the client:
Player_texture:3
Tree_texture:2
which would basically mean that player_texture is 'one version' behind, and needs to be updated.
Answer by UnbreakableOne · Jun 21, 2018 at 11:09 AM
I think he means that the image on the server is changing and he needs to update it on the client. I could be wrong, but that's what I'm getting from what he's saying
You are right.
If it's only one image, I don't think it's worth doing much and every time getting the image from the server would suffice.
If there is more, or you have lots of users, maybe store a hash of the image on the server and client and compare those.
yes I Have One Image On The Server I Just Want To Download Picture When It's Changed On The Server But Don't $$anonymous$$now How To Do It
Answer by ASPePeX · Jun 21, 2018 at 12:38 PM
You can modify your request header when asking the server for the image (https://docs.unity3d.com/ScriptReference/WWWForm-headers.html), if you add a If-Modified-Since
header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since) the server will only send the file if it was modified past the date you specify. If you use this you also have to check for the response header (https://docs.unity3d.com/ScriptReference/WWW-responseHeaders.html) to see if you get a 200 or 304. This means the image will not be tranfered if it is up to date.
At the same time you could also use an Expires
header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires) or a Cache-Control
header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) to schedule the next check for the image. This reduces the requests to the server overall.
Your answer
Follow this Question
Related Questions
Checking For Edited File 1 Answer
How to get multiple variables from page on server? 1 Answer
Integrating Watson Speech-to-Text with Unity 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers