UploadHandlerFile

class in UnityEngine.Networking

/

Inherits from:Networking.UploadHandler

Switch to Manual

Description

专门用于从给定文件读取数据并将原始字节作为请求主体发送给服务器的 UploadHandler。

您可以使用它向服务器发送大量数据,且占用的内存较少。

using System.Collections;
using UnityEngine;
using UnityEngine.Networking;

public class UHFileSample : MonoBehaviour { void Start() { StartCoroutine(UploadFileData()); }

IEnumerator UploadFileData() { using (var uwr = new UnityWebRequest("http://yourwebsite.com/upload", UnityWebRequest.kHttpVerbPUT)) { uwr.uploadHandler = new UploadHandlerFile("/path/to/file"); yield return uwr.SendWebRequest(); if (uwr.isNetworkError || uwr.isHttpError) Debug.LogError(uwr.error); else { // file data successfully sent } } } }

Constructors

UploadHandlerFile创建一个新的上传处理程序,以将来自给定文件的数据发送到服务器。

Inherited members

Variables

contentType确定将使用出站 HTTP 请求传输的默认 Content-Type 标头。
data将作为主体数据传输到远程服务器的原始数据。(只读)
progress返回上传到远程服务器的数据在上传的数据总量中占的比例。(只读)

Public Functions

DisposeSignals that this UploadHandler is no longer being used, and should clean up any resources it is using.