DownloadHandlerFile
Download handler for saving the downloaded data to file.
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Class
- Namespace: UnityEngine.Networking
- Assembly: UnityEngine.UnityWebRequestModule
- Inherits from: DownloadHandler
- Implements: IDisposable
public sealed class DownloadHandlerFile : DownloadHandler, IDisposable
Remarks
This specialized download handler writes all downloaded bytes directly to file. This can help avoid high memory usage.
You can't retrieve data from this download handler. Instead, you work with the resulting file when the download is complete.
Examples
using System.Collections;using System.IO;using UnityEngine;using UnityEngine.Networking;public class FileDownloader : MonoBehaviour { void Start () { StartCoroutine(DownloadFile()); } IEnumerator DownloadFile() { var uwr = new UnityWebRequest("https://unity3d.com/", UnityWebRequest.kHttpVerbGET); string path = Path.Combine(Application.persistentDataPath, "unity3d.html"); uwr.downloadHandler = new DownloadHandlerFile(path); yield return uwr.SendWebRequest(); if (uwr.result != UnityWebRequest.Result.Success) Debug.LogError(uwr.error); else Debug.Log("File successfully downloaded and saved to " + path); }}
Constructors
Constructor | Description |
|---|---|
| DownloadHandlerFile(System.String) | Creates a new instance and a file on disk where downloaded data will be written to. |
| DownloadHandlerFile(System.String,System.Boolean) | Creates a new instance and a file on disk where downloaded data will be written to. |
Properties
Property | Description |
|---|---|
| removeFileOnAbort | Should the created file be removed if download is aborted (manually or due to an error). Default: false. |