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

Share a zipped file...

Discussion in 'Editor & General Support' started by daveinpublic, Jul 13, 2021.

  1. daveinpublic

    daveinpublic

    Joined:
    May 24, 2013
    Posts:
    167
    Hi,

    I want to use a phone's 'share sheet' to share a zipped folder of PNGs whenever a user presses a button.

    Right now I'm using a plugin called Native Share to access the share sheet, and I'm sharing text files that I make at runtime. The code is below. But I'm not sure how to share a zipped folder that is just sitting in my assets folder. I've already compressed it, and added it to my assets folder. But I don't know how to reference it's data path. Maybe I need to connect it to a public variable through the inspector?

    Code (CSharp):
    1. string filePath = Application.persistentDataPath + "/SomeFile.txt";
    2.  
    3. new NativeShare().AddFile(filePath)
    4.         .SetSubject("Share This File")
    5.         .SetCallback((result, shareTarget) => Debug.Log("Share result: " + result + ", selected app: " + shareTarget))
    6.         .Share();
     
  2. daveinpublic

    daveinpublic

    Joined:
    May 24, 2013
    Posts:
    167
    Hi,

    So since no-one answered, I'll put the answer for anyone who's looking.

    Any file that you need a data path for, like for instance "Assets.zip", place into a folder in your Assets called "StreamingAssets".

    You can get the data path for that file by using the following code:

    Code (CSharp):
    1. string newDataPath = Application.streamingAssetsPath + "/Assets.zip";
     
    Last edited: Jul 25, 2021
    hopeful likes this.