Skip to content

Commit

Permalink
Merge pull request #6644 from ant-media/supportMp3VoD
Browse files Browse the repository at this point in the history
Support mp3 file upload
  • Loading branch information
mekya authored Oct 2, 2024
2 parents 9693a81 + a6d554b commit 0e5fc95
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
16 changes: 10 additions & 6 deletions src/main/java/io/antmedia/rest/RestServiceBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import jakarta.servlet.ServletContext;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
Expand Down Expand Up @@ -1226,10 +1227,10 @@ protected Result uploadVoDFile(String fileName, InputStream inputStream) {
String appScopeName = getScope().getName();
String fileExtension = FilenameUtils.getExtension(fileName);
try {

if ("mp4".equalsIgnoreCase(fileExtension) || "webm".equalsIgnoreCase(fileExtension)
|| "mov".equalsIgnoreCase(fileExtension) || "avi".equalsIgnoreCase(fileExtension)
|| "wmv".equalsIgnoreCase(fileExtension)) {
String[] supportedFormats = new String[] {"mp4", "webm", "mov", "avi", "mp3", "wmv"};
if (ArrayUtils.contains(supportedFormats, fileExtension)) {


IStatsCollector statsCollector = (IStatsCollector) getAppContext().getBean(IStatsCollector.BEAN_NAME);
Expand All @@ -1251,9 +1252,12 @@ protected Result uploadVoDFile(String fileName, InputStream inputStream) {
}
String vodId = RandomStringUtils.randomNumeric(24);

File savedFile = new File(String.format("%s/webapps/%s/%s", System.getProperty("red5.root"), appScopeName,
"streams/" + vodId + "." + fileExtension));

File savedFile = new File(streamsDirectory, vodId + "." + fileExtension);

if (!savedFile.toPath().normalize().startsWith(streamsDirectory.toPath().normalize())) {
throw new IOException("Entry is outside of the target directory");
}

int read = 0;
byte[] bytes = new byte[2048];
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/antmedia/whip/WhipEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public CompletableFuture<Response> startWhipPublish(@Context UriInfo uriInfo, @P

PublishParameters publishParameters = new PublishParameters(streamId);

String prefix = "Bearer ";
String prefix = "Bearer "; //there is a space after the word Bearer on purpose

if (token != null && token.toLowerCase().startsWith(prefix.toLowerCase())) {
// Extract the token by removing the prefix
token = token.substring(prefix.length());
token = token.substring(prefix.length()).trim();
}


Expand Down
24 changes: 21 additions & 3 deletions src/test/java/io/antmedia/test/rest/VoDRestServiceV2UnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void testDeleteVoDs() {


}


@Test
public void testUploadVodFile() throws FileNotFoundException, IOException {
Expand Down Expand Up @@ -338,7 +338,9 @@ public void testUploadVodFile() throws FileNotFoundException, IOException {

try (FileInputStream inputStream2 = new FileInputStream("src/test/resources/big-buck-bunny_trailer.webm")) {

restServiceReal.uploadVoDFile(fileName, inputStream2);
result = restServiceReal.uploadVoDFile(fileName, inputStream2);
assertTrue(result.isSuccess());

}


Expand All @@ -350,7 +352,23 @@ public void testUploadVodFile() throws FileNotFoundException, IOException {

assertEquals(2, restServiceReal.getTotalVodNumber().getNumber());

}
try (FileInputStream inputStream2 = new FileInputStream("src/test/resources/test.mp3")) {

result = restServiceReal.uploadVoDFile(fileName, inputStream2);
assertTrue(result.isSuccess());
}


assertTrue(f.isDirectory());

assertEquals(3, f.list().length);

assertEquals(3, store.getTotalVodNumber());

assertEquals(3, restServiceReal.getTotalVodNumber().getNumber());
}



}

Expand Down
Binary file added src/test/resources/test.mp3
Binary file not shown.

0 comments on commit 0e5fc95

Please sign in to comment.