Reputation: 237
This may be a super simple question, but for some reason I'm hesitating on the obvious solution. Should I be storing a user's local device filesystem path (for an image or video) in my remote database?
In my mobile application, users can take photos and videos and those are stored locally on their devices until they decide to upload at a later time. I am currently just tracking the local filesystem locations on their device in the local app state and not saving that information in my database. I only update my database with an image URL after it is uploaded. This works well as long as it works! In the event of crashes some users are losing their images because the local app state gets lost, and there's no remote state to recover to.
The easy, obvious solution is to just save the user's local file path to the images in my database - then even if the local state is lost they can still recover the path to those images.
Example:
{ "file_path": "/users/user1/.my_app_data/media/img.jpg" }
However, it just feels improper to store internal, device-specific information like that in my remote database, since it's meaningless without that specific device (even for the same user). In my mind, data in the server should be as device-agnostic as possible.
What is considered best practice, if there is such a thing, for this situation?
Upvotes: 0
Views: 68
Reputation: 599571
There is no singular best practice here. It all depends on your exact use-case, your tolerance for problems, and the amount of effort you're willing to spend on things.
There is no harm in storing these local paths as long as you can recognize them, and not try to use them on another user's device.
But if the local state of the device is lost, aren't the local files themselves likely to be affected too? If not, the cloud backup of the paths may be a good aid in restoring the state. But if the files are likely to also be affected, storing the paths in the cloud probably isn't very helpful and I'd skip the effort.
Upvotes: 1