IsolatedStorage Error for creating Avatar

0 votes

Hello, I am trying to predefined list of avtars for my game by using below Snippet.

public void createAvtarList(){
    for(int i=1i<9;i++){     filePath = Application.dataPath + "/Marine/Resources/MainMenu/btnAvtar" + i + ".png";
   Debug.Log(filePath);
   filePath = filePath.Replace("/Data/","/");
   Debug.Log("New File Path  " + filePath);
   if(FB.IsLoggedIn)               avatarService.CreateAvatar(("btnAvtar" + i),Login.fbUserName,filePath,avatarName,null);
            
    }
}

and I am getting below error whenever i call the createAvtarList(), from the Xcode Debugger

New File Path  /var/mobile/Applications/72643827-CF83-421E-8BF7-9EB28B3D8DAE/MY.app/Marine/Resources/MainMenu/btnAvtar1.png

(Filename: /Applications/buildAgent/work/d3d49558e4d408f4/artifacts/iPhonePlayer-armv7Generated/UnityEngineDebug.cpp Line: 53)

IsolatedStorageException: Could not find a part of the path "/var/mobile/Applications/72643827-CF83-421E-8BF7-9EB28B3D8DAE/MY.app/Marine/Resources/MainMenu/btnAvtar1.png".

  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0 

  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) [0x00000] in <filename unknown>:0 

  at System.IO.File.OpenRead (System.String path) [0x00000] in <filename unknown>:0 

  at System.IO.File.ReadAllBytes (System.String path) [0x00000] in <filename unknown>:0 

  at com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW.ExecuteMultipart (System.String name, System.String filePath, System.Collections.Generic.Dictionary`2 queryParams, System.Collections.Generic.Dictionary`2 postParams, System.Collections.Generic.Dictionary`2 headerParams, System.String url, System.String accept, App42CallBack callBack) [0x00000] in <filename unknown>:0 

  at com.shephertz.app42.paas.sdk.csharp.avatar.AvatarService.CreateAvatar (System.String avatarName, System.String userName, System.String filePath, System.String description, App42CallBack callBack) [0x00000] in <filename unknown>:0 

  at newAvatarScript.createAvtarList () [0x00000] in <filename unknown>:0 

  at newAvatarScript.OnGUI () [0x00000] in <filename unknown>:0 

 

Help me Please

Thanks

asked Apr 28, 2014 in AppWarp by marine.modi (62 points)

1 Answer

0 votes

Hi marine,

This error occurred when your file does not exist or given directory does not exist.

To check your file exists through code, you can do something like this

string root = Application.dataPath.Substring(0, Application.dataPath.Length - 4) + "Documents";
 
            if (System.IO.Directory.Exists(root))
 
            {
 
                return root; // for phone
 
            }
 
            else
 
            {
 
                return ""; // for development on PC (not phone)
 
            }
 
To learn more about how App42 Upload works in unity please read our blog.
 

 

answered Apr 28, 2014 by sshukla480 (407 points)
@sshukla Thank you. can you give me a simple static path to work for iOS or mobile device please. I am studying the tutorial but I am unable to give the exact path for the image file needed to pass as a signature.
use Application.persistentDataPath.
string path = "file://" + System.IO.Path.Combine(Application.persistentDataPath, "Images/image.png");
You can also see the related thread on unity forum.. How to get file path on ios using Unity3d
http://answers.unity3d.com/questions/156593/iphoneios-file-urls.html
@sshukla I tried to use the above code and I am getting the error As :
DirectoryNotFoundException: Could not find a part of the path "/file:/Marine/Resources/MainMenu/btnAvtar1.png".
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0
So, when i read about unity3d ios file access, the correct path is something like this.
"<path to player app bundle> / <AppName.app> / Documents"
your file path might be like this.
/var/mobile/Applications/70BC50EA-9A96-4ABE-96A8-6F309356C8E1/My.app/Documents/btnAvtar1.png

And make sure your file exists.
Go into Xcode's organizer, download your app's data directory and you can confirm if what you think should be there really is.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...