LoginSignup
0
0

More than 1 year has passed since last update.

Unity2019.1.7f1のiOSビルドで、大きいファイルがアップロード出来ない

Last updated at Posted at 2021-07-27

Unity2019.1.7f1のiOSビルドから、UnityWebRequestを使用して動画を送信しようとしたところ、アップロードされた動画が壊れ再生出来ない状態でした。

今更ながら、2019バージョンですが、備忘録的に残しておきます。

1. 結論

こちらのフォーラムを参照しました。

You could think that the issue is on our side, but in fact if we update the "streamSize" value of the generated UnityWebRequest.mm then it works at 100%.

上記のように、iOSビルドで生成された UnityWebRequest.mm の [streamSize] を大きい値に変更すると、正常に動画を送信することが出来ました。
2019.2以降では正常に動作するみたいです。

xcode_unitywebrequest.png

2. UnityWebRequestでファイルを送信する

自分用にファイル送信のコード残しておきます。

SendCapture.cs
string filePath = "端末のファイルパス";
string fileName = "test"
string uploadURL = "https://test.com/xxx"

public IEnumerator UploadFile()
{
    byte[] movieByteArray = File.ReadAllBytes(filePath);

    // formにバイナリデータを追加
    WWWForm form = new WWWForm();
    form.AddBinaryData("file", movieByteArray, fileName, "video/mp4");

    // HTTPリクエストを送る
    UnityWebRequest request = UnityWebRequest.Post(uploadURL, form);

        yield return request.SendWebRequest();
    if (request.isNetworkError || request.isHttpError)
    {
        // POSTに失敗した場合,エラーログを出力
        Debug.Log("responseCode / error : " + request.error);
    }
    else
    {
        // POSTに成功した場合,レスポンスコードを出力
        Debug.Log("responseCode / success : " + request.responseCode);
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0