Saving a file to tmp

Hi,

I’m quite new to Unity (and C#).

I am trying to fetch a file from the web. Only the request itself is important. So ideally I’d write the file to whatever is the Android equivalent to /dev/null. What should I use as the path in line 18?

using UnityEngine;
using System.Collections;
using EasyInputVR.Core;
using UnityEngine.SceneManagement;
using System.Net;


namespace EasyInputVR.Misc
{

    [AddComponentMenu("EasyInputGearVR/Miscellaneous/ExampleNavigation")]
    public class ExampleNavigation : MonoBehaviour
    {

        public void button1Submit()
        {
            WebClient webClient = new WebClient();
            webClient.DownloadFileAsync("https://myserver.com/myfile.gif?param1=1234", @"/data/data/com.mycompany.Demo5");
            SceneManager.LoadScene("tiltGearVRControllerExample");

If you actually want the file on disk (doesn’t sound like you do?) then use this to figure out where to write it:

I’m not familiar with the System.Net.WebClient architecture. When in Unity I try my hardest to act like I’m in Unity and use their networking. If you use the UnityWebRequest architecture you can fire off the request, yield on it so it gets sent, and then never do anything else with it. That might be more useful to you in this context.

1 Like

Thanks, Kurt-Dekker

May I rephrase the question: What path can I use instead /data/data/com.mycompany.Demo5 on Android (Oculus VR) so I am not getting errors.

I am not a programmer and this seems to be the only thing I need in C# for my simple project which is due very soon. I would love to dive into the documentation but am lacking the basics to understand what’s going on there.

Try Application.temporaryCachePath

I’m sure you didn’t mean disrespect, but TBH, it’s difficult for me to imagine how to come across more blase and dismissive in a coding forum than with above comment. If you can’t be bothered to learn, GTFO.

-ch

1 Like

Thanks a lot for your reply, csofranz.
In fact I didn’t mean to be disrespectful as my wording could imply. I value the knowledge and experience of you guys.

Here’s what I did:
In fact, I was using the wrong approch wit the WebClient.

        UnityWebRequest www = UnityWebRequest.Get(PAYLOAD);
        yield return www.SendWebRequest();

as referenced in the documentation @Kurt-Dekker linked, without the need to save any data in the file system.
Thanks guys!

1 Like