UploadFileForUser using Stream as parameter(Unity 3D)

0 votes

Hi!

Using url(string) as parameter, works correctly, but using Stream it doesn't.

Code:

//give to ReadStream() the picture in bytes...

Stream ReadStream(byte[] bytes){
        Stream s = new MemoryStream();
        for (int i = 0i < bytes.Lengthi++)
        {
            s.WriteByte(bytes[i]);
        }
        s.Position = 0;
        s.Close();
        return s;
    }

 

And send it:

Stream stream = GetStream(); //here does many things and finally ReadStream to get the bytes array

uploadService.UploadFileForUser("picture","name",stream,UploadFileType.IMAGE,"picture description",new UploadPictureCallBack());

Error:

NullReferenceException: Object reference not set to an instance of an object

com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW.ExecuteMultipart (System.String name, System.IO.Stream stream, 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)
com.shephertz.app42.paas.sdk.csharp.upload.UploadService.UploadFile (System.String name, System.IO.Stream inputStream, System.String fileType, System.String description, App42CallBack callBack)
PictureUploader.UploadProfilePicture (System.IO.Stream stream) (at Assets/EtorkiGames/Assets/Scripts/Others/PictureUploader.cs:74)
PictureUploader.Update () (at Assets/EtorkiGames/Assets/Scripts/Others/PictureUploader.cs:22)
 
Any help? :)
asked Aug 22, 2014 in App42 Cloud API-BaaS by etorkigames (25 points)

1 Answer

0 votes
Hi Etorkigames,
 
This exception occurs when your Stream object is empty or null as shown in below code snippet.
Stream stream  = new MemoryStream();
upload.UploadFile("File-1",stream,"image","My File",callBack);
 
Please use correct Stream object something like this and pass proper stream object pointing to valid file.
 
 
 
Stream stream  = new FileStream(@"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg", FileMode.Open);
upload.UploadFile("File-1",stream,"image","My File",callBack);
 
Thanks
/Naresh

 

answered Aug 23, 2014 by naresh (350 points)
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
...