Parse.com上的文件上传无效

时间:2014-10-07 11:00:26

标签: c# android file-upload unity3d parse-platform

我一直在使用C#在Unity3D中开发游戏。所以我设置游戏上传游戏保存文件 每2分钟解析一次。当我在Unity中运行代码时,它工作正常,它在本地保存游戏保存文件,并且每2分钟将其上传到Parse,它也指向正在玩游戏的用户。虽然当我在移动设备上运行游戏时文件没有上传,但我在过去的半小时内一直刷新我的解析数据对象,但我仍然没有得到任何东西。

以下是代码:

void Start () 
{
    if (ParseUser.CurrentUser != null)
    {
        gapTest = true;
    }
}

void Update () 
{
    if(gapTest)
    {
        StartCoroutine(UploadFile());
    }
       if (uploadSaveFile)
    {
        OnZipComplete();
        uploadSaveFile = false;
    }
    else if (createNewSaveFile)
    {
        CreateNewSaveFile();
        createNewSaveFile = false;
    }
}

IEnumerator UploadFile()
{
    gapTest = false;
    yield return new WaitForSeconds (120.0F);
    if(ParseUser.CurrentUser != null)
    {
        OnZipComplete();
    }
    gapTest = true;
}

void OnZipComplete()
{
    var query = ParseObject.GetQuery("GameSave").WhereEqualTo("UserObjectId", ParseUser.CurrentUser);

    if (existingGameSave == null)
    {
        query.FindAsync().ContinueWith(t =>
        {
            IEnumerable<ParseObject> results = t.Result;

            int resultCount = 0;
            foreach (var result in results)
            {
                if (resultCount > 0)
                {
                    Debug.LogError("Found more than one save file for user!");
                }
                else
                {
                    resultCount++;
                    existingGameSave = result;
                    uploadSaveFile = true;
                }
            }

            if (resultCount == 0)
            {
                createNewSaveFile = true;
            }
        });
    }
    else
    {
        UpdateExistingSaveFile();
    }
}

private void CreateNewSaveFile()
{
    //upload the file to parse
    zipPath = Application.persistentDataPath + "/SaveGame.zip";

    byte[] data = System.Text.Encoding.UTF8.GetBytes(zipPath);
    ParseFile GameSave = new ParseFile("GameSave.zip", data);

    var gameSave = new ParseObject("GameSave");
    gameSave["UserObjectId"] = ParseUser.CurrentUser;
    gameSave["GameSaveFile"] = GameSave;
    Task saveTask = gameSave.SaveAsync();

    Debug.Log("New Game save file has been uploaded");
}

void UpdateExistingSaveFile()
{
    //upload the file to parse
    UserIdFile = Application.persistentDataPath + "/UserId.txt";
    zipPath = Application.persistentDataPath + "/SaveGame.zip";

    byte[] data = System.Text.Encoding.UTF8.GetBytes(zipPath);
    ParseFile GameSave = new ParseFile("GameSave.zip", data);               
    existingGameSave["GameSaveFile"] = GameSave;
    Task saveTask = existingGameSave.SaveAsync();

    Debug.Log("Existing Game save file has been uploaded");
}

1 个答案:

答案 0 :(得分:0)

这可能是与Android设备上的权限相关的问题。

转到构建设置&gt;播放器设置&gt;其他设置,并检查&#34;写访问&#34;,默认情况下,它是内部的,这意味着该路径仅用于开发目的。

尝试将写访问设置为外部(SD卡)或将WRITE_ EXTERNAL_STORAGE权限添加到AndroidManifest.xml中。如果您的数据实际上是在设备上写的,请查看SD卡的Android / file / com.your.appid /文件。

如果正在编写数据,那么它肯定会上传到parse.com。