UnityWebReques / bytes

Hi.
I did not understand how I should do this.
“UnityWebRequest” “bytes” is not allowed what should I use

    private IEnumerator ShareFileUsingShareSheetCo()
    {
        UnityWebRequest www = new UnityWebRequest(Application.streamingAssetsPath + "/" + mFileName);
        yield return www;
        string filePath = Path.Combine(Application.temporaryCachePath, mFileName);
        File.WriteAllBytes(filePath, www.bytes);
        new NativeShare().AddFile(filePath).Share();
    }

You did not send your web request. You have to use SendWebRequest and yield the result of that method.

yield return www.SetWebRequest();

Also you used the constructor of the UnityWebRequest manually. So you have to setup the whole request yourself. You did not specify the request method (GET / POST / …) and you also did not specify a download handler. In most cases you don’t want to use the constructor manually. Instead use one of the static utility methods which create a request for a certain method. In most cases you just want to use Get. See the example in the documentation.

thx for the answer. but I couldn’t understand. I know very little about this.

the old caliber was like this

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;


public class Share : MonoBehaviour
{
    public string mFileName = "001.mp3";
    public void ClichkShare()
    {
        StartCoroutine(ShareFileUsingShareSheetCo());
    }
    private IEnumerator ShareFileUsingShareSheetCo()
    {
        WWW www = new WWW(Application.streamingAssetsPath + "/" + mFileName);
        yield return www;
        string filePath = Path.Combine(Application.temporaryCachePath, mFileName);
        File.WriteAllBytes(filePath, www.bytes);
        new NativeShare().AddFile(filePath).Share();
    }
}

“bytes” does not allow when I do this
:frowning:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.Networking;

public class Share : MonoBehaviour
{
    public string mFileName = "001.mp3";
    public void ClichkShare()
    {
        StartCoroutine(ShareFileUsingShareSheetCo());
    }
    private IEnumerator ShareFileUsingShareSheetCo()
    {
        UnityWebRequest www = new UnityWebRequest(Application.streamingAssetsPath + "/" + mFileName);
        yield return www;
        string filePath = Path.Combine(Application.temporaryCachePath, mFileName);
        File.WriteAllBytes(filePath, www.bytes);
        new NativeShare().AddFile(filePath).Share();
    }
}

What you want is “data” property on download handler.
What you want is:

var bytes = www.downloadHandler.data;

Thanks for the help, but where and how should I post this? i couldn’t get it to work