public void TestGet() { String soundName = "mp3_test_" + DateTime.Now.Millisecond.ToString(); ResourceId mp3ResourceId; try { mp3ResourceId = Client.MediaApi.Upload(mp3FilePath, soundName); } catch (BadRequestException e) { mp3ResourceId = new ResourceId { Id = SelectIdFromBadRequestErrorString(e.ApiErrorMessage.Message) }; } Media media = Client.MediaApi.Get(mp3ResourceId.Id); Assert.NotNull(media); Assert.True(media.Name.Contains("mp3_test_")); Assert.AreEqual(media.Id, mp3ResourceId.Id); Assert.AreEqual(media.MediaType, MediaType.MP3); Assert.NotNull(media.LengthInBytes); Assert.NotNull(media.Created); Assert.NotNull(media.PublicUrl); media = Client.MediaApi.Get(mp3ResourceId.Id, "id,created"); Assert.Null(media.Name); Assert.Null(media.LengthInBytes); Assert.Null(media.PublicUrl); Assert.Null(media.MediaType); }
public void TestGetDataById() { String soundName = "mp3_test_" + DateTime.Now.Millisecond.ToString(); ResourceId mp3ResourceId; try { mp3ResourceId = Client.MediaApi.Upload(mp3FilePath, soundName); } catch (BadRequestException e) { mp3ResourceId = new ResourceId { Id = SelectIdFromBadRequestErrorString(e.ApiErrorMessage.Message) }; } MemoryStream ms = (MemoryStream)Client.MediaApi.GetData(mp3ResourceId.Id, MediaType.MP3); string pathToSaveNewFile = mp3FilePath.Replace("train.mp3", "mp3_sound.mp3"); File.WriteAllBytes(pathToSaveNewFile, ms.ToArray()); }