Skip to content

Instantly share code, notes, and snippets.

@voxelbustersold
Created January 4, 2019 07:53
Show Gist options
  • Save voxelbustersold/df0a84ef7d890da0086b3b1e62e33f55 to your computer and use it in GitHub Desktop.
Save voxelbustersold/df0a84ef7d890da0086b3b1e62e33f55 to your computer and use it in GitHub Desktop.
Copy any file to Persistent Path
// Namespace for using utility functions
using VoxelBusters.InstagramKit.Common.Utility;
// Path can be from local or web
private void DownloadFileToPersistentPath(string filePath, string targetFileName)
{
// Downloading if the file doesn't exist
if (!FileOperations.Exists (Application.persistentDataPath + "/" + targetFileName))
{
// Download file from given path
DownloadAsset _newDownload = new DownloadAsset (new URL (filePath), true);
_newDownload.OnCompletion = (WWW _www, string _error) => {
Debug.Log (string.Format ("[DownloadAsset] Asset download completed. Error= {0}.", _error.GetPrintableString ()));
FileOperations.WriteAllBytes (Application.persistentDataPath + "/" + targetFileName, _www.bytes);
};
// Start download
_newDownload.StartRequest ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment