From a79d34e7695da4399f912c291167c1168e7ea9ea Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Wed, 16 Jul 2025 11:14:34 +0530 Subject: [PATCH 1/5] Enhance FileUploader to support additional MIME types and add uploadFile test in AssetAPITest --- .../contentstack/cms/stack/FileUploader.java | 33 +++++++++++++++++-- .../contentstack/cms/stack/AssetAPITest.java | 21 ++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/contentstack/cms/stack/FileUploader.java b/src/main/java/com/contentstack/cms/stack/FileUploader.java index bdfc65bb..84cd9f30 100644 --- a/src/main/java/com/contentstack/cms/stack/FileUploader.java +++ b/src/main/java/com/contentstack/cms/stack/FileUploader.java @@ -7,12 +7,34 @@ import java.io.File; import java.io.IOException; import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; import javax.activation.MimetypesFileTypeMap; public class FileUploader { + // Static map for common file extensions to MIME types + private static final Map EXTENSION_TO_MIME; + static { + EXTENSION_TO_MIME = new HashMap<>(); + EXTENSION_TO_MIME.put(".svg", "image/svg+xml"); + EXTENSION_TO_MIME.put(".webp", "image/webp"); + EXTENSION_TO_MIME.put(".json", "application/json"); + EXTENSION_TO_MIME.put(".woff", "font/woff"); + EXTENSION_TO_MIME.put(".woff2", "font/woff2"); + EXTENSION_TO_MIME.put(".ttf", "font/ttf"); + EXTENSION_TO_MIME.put(".otf", "font/otf"); + EXTENSION_TO_MIME.put(".eot", "application/vnd.ms-fontobject"); + EXTENSION_TO_MIME.put(".mp4", "video/mp4"); + EXTENSION_TO_MIME.put(".m4a", "audio/mp4"); + EXTENSION_TO_MIME.put(".mkv", "video/x-matroska"); + EXTENSION_TO_MIME.put(".webm", "video/webm"); + EXTENSION_TO_MIME.put(".ico", "image/x-icon"); + EXTENSION_TO_MIME.put(".csv", "text/csv"); + EXTENSION_TO_MIME.put(".md", "text/markdown"); + } public MultipartBody createMultipartBody(String filePath, String parentUid, String title, String description, String[] tags) { MultipartBody.Builder builder = new MultipartBody.Builder(); @@ -47,9 +69,16 @@ public MultipartBody createMultipartBody(String filePath, String parentUid, Stri // Helper method to get content type of file private String getContentType(File file) { + String name = file.getName().toLowerCase(); + int dot = name.lastIndexOf('.'); + if (dot != -1) { + String ext = name.substring(dot); + String mime = EXTENSION_TO_MIME.get(ext); + if (mime != null) return mime; + } try { - java.nio.file.Path source = Paths.get(file.toString()); - MimetypesFileTypeMap m = new MimetypesFileTypeMap(source.toString()); + java.nio.file.Path source = java.nio.file.Paths.get(file.toString()); + javax.activation.MimetypesFileTypeMap m = new javax.activation.MimetypesFileTypeMap(source.toString()); return m.getContentType(file); } catch (IOException e) { throw new RuntimeException("Failed to determine content type of file", e); diff --git a/src/test/java/com/contentstack/cms/stack/AssetAPITest.java b/src/test/java/com/contentstack/cms/stack/AssetAPITest.java index cc149d8d..69910974 100644 --- a/src/test/java/com/contentstack/cms/stack/AssetAPITest.java +++ b/src/test/java/com/contentstack/cms/stack/AssetAPITest.java @@ -11,6 +11,12 @@ import java.io.IOException; import java.util.HashMap; import java.util.Objects; +import com.contentstack.cms.stack.FileUploader; +import org.junit.jupiter.api.Test; +import java.io.File; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; @Tag("API") class AssetAPITest { @@ -358,4 +364,19 @@ void testFetchSubfoldersByParentFolderPojo() { Assertions.assertEquals("https://api.contentstack.io/v3/assets?folder=test_folder&query={parent_uid%3Dparent_uid,%20is_dir%3Dtrue}&include_folders=true", request.url().toString()); } + @Test + @Disabled("disabled to avoid unnecessary asset creation, Tested working fine") + void uploadFile() throws Exception { + Contentstack contentstack = new Contentstack.Builder().build(); + Stack stack = contentstack.stack(API_KEY, MANAGEMENT_TOKEN); + Asset asset = stack.asset(); + String fileName = "/Users/reeshika.hosmani/Downloads/surf-svgrepo-com.svg", parentFolder = "bltd1150f1f7d9411e5", title = "Vacation icon"; + String[] tags = {"icon"}; + Response response = asset.uploadAsset(fileName,parentFolder,title,"",tags).execute(); + if(response.isSuccessful()){ + System.out.println("uploaded asset successfully:" + response.body().string()); + } else { + System.out.println("Error in uploading" + response.errorBody().string()); + } + } } From d71810126a0e5112de93967fc66a50c3186caa61 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Wed, 16 Jul 2025 14:29:25 +0530 Subject: [PATCH 2/5] Update version to 1.7.0-beta-1 and modify Maven publishing workflow. Changed distribution management settings and updated plugin configurations for central publishing. Adjusted GitHub Actions to publish on push to specific branch. --- .github/workflows/maven-publish.yml | 15 +++++++++------ pom.xml | 29 ++++++++++++++--------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 54561a3c..8f89dea9 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -1,9 +1,12 @@ name: Publish package to the Maven Central Repository on: - release: - types: - - created + push: + branches: + - fix/DX-3251-release-workflow-fix + # release: + # types: + # - created jobs: publish-maven: runs-on: ubuntu-latest @@ -17,7 +20,7 @@ jobs: with: java-version: "11" distribution: "adopt" - server-id: ossrh + server-id: central server-username: MAVEN_USERNAME server-password: MAVEN_PASSWORD gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} @@ -25,8 +28,8 @@ jobs: - name: Publish to the Maven Central Repository run: mvn --batch-mode -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }} deploy env: - MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} publish-github: runs-on: ubuntu-latest diff --git a/pom.xml b/pom.xml index d3e28f20..ccc09d7a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ cms jar contentstack-management-java - 1.7.0 + 1.7.0-beta-1 Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an API-first approach @@ -61,23 +61,23 @@ - + - - - - + + github + GitHub Apache Maven Packages + https://maven.pkg.github.com/contentstack/contentstack-management-java + ossrh Apache Maven Packages Release https://oss.sonatype.org/service/local/staging/deploy/maven2/ - + --> 1.0.0 @@ -100,7 +100,6 @@ 3.3 1.5 3.8.0 - 1.6.13 2.5.3 @@ -337,14 +336,14 @@ - org.sonatype.plugins - nexus-staging-maven-plugin - ${nexus-staging-maven-plugin.version} + org.sonatype.central + central-publishing-maven-plugin + 0.8.0 true - ossrh - https://oss.sonatype.org/ - true + central + true + published From d792008f927a15c95b493c78f8cf8d0ad20c309c Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Wed, 16 Jul 2025 14:45:11 +0530 Subject: [PATCH 3/5] For testing purpose particular branch was added --- .github/workflows/maven-publish.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 8f89dea9..4c5577e1 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -1,12 +1,9 @@ name: Publish package to the Maven Central Repository on: - push: - branches: - - fix/DX-3251-release-workflow-fix - # release: - # types: - # - created + release: + types: + - created jobs: publish-maven: runs-on: ubuntu-latest From d8718edca8297d8e18d43687e030722043ea326a Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Wed, 16 Jul 2025 14:46:38 +0530 Subject: [PATCH 4/5] version bump --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ccc09d7a..96e5fdd5 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ cms jar contentstack-management-java - 1.7.0-beta-1 + 1.7.0 Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an API-first approach From a850dcfc0c4141ad8ce66d3bdb0a22f3bd2bc17d Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Wed, 16 Jul 2025 14:50:26 +0530 Subject: [PATCH 5/5] version bump --- changelog.md | 6 ++++++ pom.xml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 0207b743..3212b721 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## v1.7.1 + +### Jul 21, 2025 + +- FileUpload method fix + ## v1.7.0 ### Jul 07, 2025 diff --git a/pom.xml b/pom.xml index d3e28f20..ffa06f37 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ cms jar contentstack-management-java - 1.7.0 + 1.7.1 Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an API-first approach