Skip to content

Commit 82d4f75

Browse files
authored
Merge pull request #169 from contentstack/staging
DX | 17-07-2025 | Release
2 parents 5ec2660 + bc631f1 commit 82d4f75

File tree

5 files changed

+75
-20
lines changed

5 files changed

+75
-20
lines changed

.github/workflows/maven-publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ jobs:
1717
with:
1818
java-version: "11"
1919
distribution: "adopt"
20-
server-id: ossrh
20+
server-id: central
2121
server-username: MAVEN_USERNAME
2222
server-password: MAVEN_PASSWORD
2323
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
2424
gpg-passphrase: GPG_PASSPHRASE
2525
- name: Publish to the Maven Central Repository
2626
run: mvn --batch-mode -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }} deploy
2727
env:
28-
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
29-
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
28+
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
29+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
3030
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
3131
publish-github:
3232
runs-on: ubuntu-latest

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v1.7.1
4+
5+
### Jul 21, 2025
6+
7+
- FileUpload method fix
8+
39
## v1.7.0
410

511
### Jul 07, 2025

pom.xml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<artifactId>cms</artifactId>
88
<packaging>jar</packaging>
99
<name>contentstack-management-java</name>
10-
<version>1.7.0</version>
10+
<version>1.7.1</version>
1111
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
1212
API-first approach
1313
</description>
@@ -61,23 +61,23 @@
6161
</developer>
6262
</developers>
6363

64-
<distributionManagement>
64+
<!-- <distributionManagement>
6565
<snapshotRepository>
6666
<id>ossrh</id>
6767
<name>Apache Maven Packages Snapshot</name>
6868
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
6969
</snapshotRepository>
70-
<!-- <snapshotRepository>-->
71-
<!-- <id>github</id>-->
72-
<!-- <name>GitHub Apache Maven Packages</name>-->
73-
<!-- <url>https://maven.pkg.github.com/contentstack/contentstack-management-java</url>-->
74-
<!-- </snapshotRepository> -->
70+
<snapshotRepository>
71+
<id>github</id>
72+
<name>GitHub Apache Maven Packages</name>
73+
<url>https://maven.pkg.github.com/contentstack/contentstack-management-java</url>
74+
</snapshotRepository>
7575
<repository>
7676
<id>ossrh</id>
7777
<name>Apache Maven Packages Release</name>
7878
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
7979
</repository>
80-
</distributionManagement>
80+
</distributionManagement> -->
8181

8282
<properties>
8383
<sdk.version>1.0.0</sdk.version>
@@ -100,7 +100,6 @@
100100
<maven-site-plugin.version>3.3</maven-site-plugin.version>
101101
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
102102
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
103-
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
104103
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
105104
</properties>
106105

@@ -338,14 +337,14 @@
338337
</configuration>
339338
</plugin>
340339
<plugin>
341-
<groupId>org.sonatype.plugins</groupId>
342-
<artifactId>nexus-staging-maven-plugin</artifactId>
343-
<version>${nexus-staging-maven-plugin.version}</version>
340+
<groupId>org.sonatype.central</groupId>
341+
<artifactId>central-publishing-maven-plugin</artifactId>
342+
<version>0.8.0</version> <!-- or latest -->
344343
<extensions>true</extensions>
345344
<configuration>
346-
<serverId>ossrh</serverId>
347-
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
348-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
345+
<publishingServerId>central</publishingServerId>
346+
<autoPublish>true</autoPublish>
347+
<waitUntil>published</waitUntil>
349348
</configuration>
350349
</plugin>
351350
<plugin>

src/main/java/com/contentstack/cms/stack/FileUploader.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,34 @@
77
import java.io.File;
88
import java.io.IOException;
99
import java.nio.file.Paths;
10+
import java.util.HashMap;
11+
import java.util.Map;
1012
import java.util.Objects;
1113

1214
import javax.activation.MimetypesFileTypeMap;
1315

1416
public class FileUploader {
1517

18+
// Static map for common file extensions to MIME types
19+
private static final Map<String, String> EXTENSION_TO_MIME;
20+
static {
21+
EXTENSION_TO_MIME = new HashMap<>();
22+
EXTENSION_TO_MIME.put(".svg", "image/svg+xml");
23+
EXTENSION_TO_MIME.put(".webp", "image/webp");
24+
EXTENSION_TO_MIME.put(".json", "application/json");
25+
EXTENSION_TO_MIME.put(".woff", "font/woff");
26+
EXTENSION_TO_MIME.put(".woff2", "font/woff2");
27+
EXTENSION_TO_MIME.put(".ttf", "font/ttf");
28+
EXTENSION_TO_MIME.put(".otf", "font/otf");
29+
EXTENSION_TO_MIME.put(".eot", "application/vnd.ms-fontobject");
30+
EXTENSION_TO_MIME.put(".mp4", "video/mp4");
31+
EXTENSION_TO_MIME.put(".m4a", "audio/mp4");
32+
EXTENSION_TO_MIME.put(".mkv", "video/x-matroska");
33+
EXTENSION_TO_MIME.put(".webm", "video/webm");
34+
EXTENSION_TO_MIME.put(".ico", "image/x-icon");
35+
EXTENSION_TO_MIME.put(".csv", "text/csv");
36+
EXTENSION_TO_MIME.put(".md", "text/markdown");
37+
}
1638

1739
public MultipartBody createMultipartBody(String filePath, String parentUid, String title, String description, String[] tags) {
1840
MultipartBody.Builder builder = new MultipartBody.Builder();
@@ -47,9 +69,16 @@ public MultipartBody createMultipartBody(String filePath, String parentUid, Stri
4769

4870
// Helper method to get content type of file
4971
private String getContentType(File file) {
72+
String name = file.getName().toLowerCase();
73+
int dot = name.lastIndexOf('.');
74+
if (dot != -1) {
75+
String ext = name.substring(dot);
76+
String mime = EXTENSION_TO_MIME.get(ext);
77+
if (mime != null) return mime;
78+
}
5079
try {
51-
java.nio.file.Path source = Paths.get(file.toString());
52-
MimetypesFileTypeMap m = new MimetypesFileTypeMap(source.toString());
80+
java.nio.file.Path source = java.nio.file.Paths.get(file.toString());
81+
javax.activation.MimetypesFileTypeMap m = new javax.activation.MimetypesFileTypeMap(source.toString());
5382
return m.getContentType(file);
5483
} catch (IOException e) {
5584
throw new RuntimeException("Failed to determine content type of file", e);

src/test/java/com/contentstack/cms/stack/AssetAPITest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
import java.io.IOException;
1212
import java.util.HashMap;
1313
import java.util.Objects;
14+
import com.contentstack.cms.stack.FileUploader;
15+
import org.junit.jupiter.api.Test;
16+
import java.io.File;
17+
import java.util.Map;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
1420

1521
@Tag("API")
1622
class AssetAPITest {
@@ -358,4 +364,19 @@ void testFetchSubfoldersByParentFolderPojo() {
358364
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());
359365
}
360366

367+
@Test
368+
@Disabled("disabled to avoid unnecessary asset creation, Tested working fine")
369+
void uploadFile() throws Exception {
370+
Contentstack contentstack = new Contentstack.Builder().build();
371+
Stack stack = contentstack.stack(API_KEY, MANAGEMENT_TOKEN);
372+
Asset asset = stack.asset();
373+
String fileName = "/Users/reeshika.hosmani/Downloads/surf-svgrepo-com.svg", parentFolder = "bltd1150f1f7d9411e5", title = "Vacation icon";
374+
String[] tags = {"icon"};
375+
Response<ResponseBody> response = asset.uploadAsset(fileName,parentFolder,title,"",tags).execute();
376+
if(response.isSuccessful()){
377+
System.out.println("uploaded asset successfully:" + response.body().string());
378+
} else {
379+
System.out.println("Error in uploading" + response.errorBody().string());
380+
}
381+
}
361382
}

0 commit comments

Comments
 (0)