By using AWS re:Post, you agree to the Terms of Use

Welcome to AWS re:Post

re:Post gives you access to a vibrant community that helps you become even more successful on AWS

Learn AWS faster by following popular topics

see all
1/18

Recent questions

see all
1/18

S3 Get object not working properly in Unity

I am using AWS SDK .NET for Unity to download zip files from S3. I implemented the get method just as this tutorial for .NET https://docs.aws.amazon.com/AmazonS3/latest/userguide/download-objects.html But when I call the method with ReadObjectDataAsync().Wait(); Unity stops and crashes, like is in an infinite loop. This is my code, has a different name but is practically the same: /// <summary> /// Start is called before the first frame update /// </summary> void Start() { customSongsManager = gameObject.GetComponent<CustomSongsManager>(); GetZip(S3SampleFile).Wait(); } /// <summary> /// Get Object from S3 Bucket /// </summary> public async Task GetZip(string pFile) { string folder = "Assets/Audio/Custom/"; try { GetObjectRequest request = new GetObjectRequest { BucketName = S3Bucket, Key = pFile }; using (GetObjectResponse response = await S3Client.GetObjectAsync(request)) using (Stream responseStream = response.ResponseStream) { string title = response.Metadata["x-amz-meta-title"]; // Assume you have "title" as medata added to the object. string contentType = response.Headers["Content-Type"]; Debug.Log("Object metadata, Title: " + title); Debug.Log("Content type: " + contentType); if (responseStream != null) { using (BinaryReader bReader = new BinaryReader(response.ResponseStream)) { byte[] buffer = bReader.ReadBytes((int)response.ResponseStream.Length); File.WriteAllBytes(folder + S3SampleFile, buffer); Debug.Log("Writed all bytes"); StartCoroutine(customSongsManager.ReadDownloadedSong(folder + S3SampleFile)); } } } } catch (AmazonS3Exception e) { // If bucket or object does not exist Debug.Log("Error encountered ***. Message:"+ e.Message + " when reading object"); } catch (Exception e) { Debug.Log("Unknown encountered on server. Message:"+ e.Message + " when reading object"); } } The game crashes in this line: using (GetObjectResponse response = await S3Client.GetObjectAsync(request))
0
answers
0
votes
2
views
asked 4 hours ago