How do I upload files from a phone to my Amazon S3 server?

I’m developing a mobile app with Unity and using S3 to store and retrieve assets, I can download asset bundles just fine from the server to the phone, but how do I upload files from the phone to the server?

I used the PostObject function from the AWS Unity SDK, and it works fine if I upload from the computer as I know the directory, but I’m not sure how to get the phone’s photo gallery to upload to the s3 server.

This is the PostObject function

public void PostObject(string fileName)
{    
   ResultText.text = "Retrieving the file";
   var stream = new FileStream("file://" + Application.streamingAssetsPath + "/" + fileName,
   FileMode.Open, FileAccess.Read, FileShare.Read);
   Debug.Log("kek");
   ResultText.text += "\nCreating request object";
   var request = new PostObjectRequest()
   {
       Bucket = S3BucketName,
       Key = fileName,
       InputStream = stream,
       CannedACL = S3CannedACL.Private,
       Region = _S3Region
   };

   ResultText.text += "\nMaking HTTP post call";

   Client.PostObjectAsync(request, (responseObj) =>
   {
       if (responseObj.Exception == null)
       {
           ResultText.text += string.Format("\nobject {0} posted to bucket {1}",
           responseObj.Request.Key, responseObj.Request.Bucket);
       }
       else
       {
           ResultText.text += "\nException while posting the result object";
           ResultText.text += string.Format("\n receieved error {0}",
           responseObj.Response.HttpStatusCode.ToString());
       }
   });
}

And this is where I’m using it to upload the picture taken from the phone to the server

public void TakePicture(int maxSize)
{
   NativeCamera.Permission permission = NativeCamera.TakePicture((path) =>
   {
       Debug.Log("Image path: " + path);
       if (path != null)
       {
           // Create a Texture2D from the captured image
           Texture2D imageTexture = NativeCamera.LoadImageAtPath(path, maxSize);
           if (imageTexture == null)
           {
               Debug.Log("Couldn't load texture from " + path);
               return;
           }

           //picturePreview.gameObject.SetActive(true);
           //picturePreview.texture = imageTexture;

           Texture2D readableTexture = DuplicateTexture(imageTexture);

           StartCoroutine(AddImageJob(readableTexture));
           //Saves taken photo to the Image Gallery
           if (isSaveFiles)
           {
               NativeGallery.SaveImageToGallery(imageTexture, "AReview", "test");

               //Upload to Amazon S3
               aws.PostObject(imageTexture.name);
               aws.PostObject("test");
           }
       }
   }, maxSize);

   Debug.Log("Permission result: " + permission);
}

Any clues?

Thank you.

Have you studied the output in the logs, such as either XCode if you’re doing an iPhone or adb logcat if you’re doing Android? There are likely exceptions or notices being thrown if it’s a networking or permissions issue.

Also, break the two problems in half: getting something from a gallery is very complex, getting something uploaded to an authenticating server is also complex. Put a little tiny blob of data in your game (hard-wired) and work on the uploading part first. Get that tiny blob up and loaded onto the server, and while doing so, see if any error messages are returned from any of the AWS SDK objects. I’m unfamiliar with their API but I am sure they have some way of telling you why something failed.