Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Downsize/compress image on upload to Firebase?

Discussion in 'Formats & External Tools' started by Radical_boy, Aug 20, 2021.

  1. Radical_boy

    Radical_boy

    Joined:
    Jan 30, 2021
    Posts:
    8
    The images that i upload to FIrebase are pretty big and i need way to make them smalles in bytes size. I only found stuff about Bitmap on other sites but unity does not recognise it and i dont know why. I use the Unity asses SimpleFile Browser for the selection of the file
    Code (CSharp):
    1. IEnumerator ShowLoadDialogCoroutine() { yield return FileBrowser.WaitForLoadDialog(FileBrowser.PickMode.FilesAndFolders, true, null, null, "Load Files and Folders", "Load"); Debug.Log(FileBrowser.Success);
    2.  
    3.      if (FileBrowser.Success)
    4.      {
    5.          for (int i = 0; i < FileBrowser.Result.Length; i++)
    6.              Debug.Log(FileBrowser.Result[i]);
    7.          Debug.Log("File Selected");
    8.        
    9.          byte[] bytes = FileBrowserHelpers.ReadBytesFromFile(FileBrowser.Result[0]);
    10.          long x = FileBrowserHelpers.GetFilesize(FileBrowser.Result[0]);
    11.          Debug.LogError(x);
    12.          var newMetaData = new MetadataChange();
    13.          newMetaData.ContentType = "image/jpeg";
    14.          if (haspp == 1)
    15.          {
    16.              StartCoroutine(DeleteProfilePic());
    17.          }
    18.        
    19.          StorageReference uploadRef = reference.Child("profilePictures").Child(User.UserId).Child("picture");
    20.          Debug.Log("File Upload started");
    21.        
    22.          uploadRef.PutBytesAsync(bytes, newMetaData).ContinueWithOnMainThread((task) =>
    23.          {
    24.              if (task.IsFaulted || task.IsCanceled)
    25.              {
    26.                  Debug.Log(task.Exception);
    27.              }
    28.              else
    29.              {
    30.                  Debug.Log("File uploaded succesfully");
    31.              }
    32.          });
    33.          StorageReference image = reference.Child("profilePictures").Child(User.UserId).Child("picture");
    34.          image.GetDownloadUrlAsync().ContinueWithOnMainThread(task =>
    35.          {
    36.              if (!task.IsCanceled && !task.IsFaulted)
    37.              {
    38.                  StartCoroutine(LoadImage(task.Result.ToString()));
    39.              }
    40.              else
    41.              {
    42.                  Debug.Log(task.Exception);
    43.              }
    44.          });
    45.      }
    46. }`
    if anybody knows a way i would be so greatful