aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-05-30 10:39:21 -0700
committerAnton Tananaev <anton@traccar.org>2023-05-30 10:39:29 -0700
commit854afb13bd8115a17b9c6c4cf739707313a709cf (patch)
treeb4805b21481b95e4ed0c6740718a2053678017ee /src/main/java
parentf7ea4c3829a8ca982af4ce6999f63d212769119d (diff)
downloadtrackermap-server-854afb13bd8115a17b9c6c4cf739707313a709cf.tar.gz
trackermap-server-854afb13bd8115a17b9c6c4cf739707313a709cf.tar.bz2
trackermap-server-854afb13bd8115a17b9c6c4cf739707313a709cf.zip
Support file uploading
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/api/resource/ServerResource.java36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/api/resource/ServerResource.java b/src/main/java/org/traccar/api/resource/ServerResource.java
index f334b7a21..dcb059b69 100644
--- a/src/main/java/org/traccar/api/resource/ServerResource.java
+++ b/src/main/java/org/traccar/api/resource/ServerResource.java
@@ -16,12 +16,14 @@
package org.traccar.api.resource;
import org.traccar.api.BaseResource;
+import org.traccar.config.Config;
+import org.traccar.config.Keys;
import org.traccar.database.OpenIdProvider;
-import org.traccar.helper.model.UserUtil;
-import org.traccar.mail.MailManager;
import org.traccar.geocoder.Geocoder;
import org.traccar.helper.Log;
import org.traccar.helper.LogAction;
+import org.traccar.helper.model.UserUtil;
+import org.traccar.mail.MailManager;
import org.traccar.model.Server;
import org.traccar.model.User;
import org.traccar.session.cache.CacheManager;
@@ -36,12 +38,20 @@ import javax.annotation.security.PermitAll;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.TimeZone;
@@ -52,6 +62,9 @@ import java.util.TimeZone;
public class ServerResource extends BaseResource {
@Inject
+ private Config config;
+
+ @Inject
private CacheManager cacheManager;
@Inject
@@ -119,4 +132,23 @@ public class ServerResource extends BaseResource {
return Arrays.asList(TimeZone.getAvailableIDs());
}
+ @Path("file/{path}")
+ @POST
+ @Consumes("*/*")
+ public Response uploadImage(@PathParam("path") String path, File inputFile) throws IOException, StorageException {
+ permissionsService.checkAdmin(getUserId());
+ String root = config.getString(Keys.WEB_OVERRIDE, config.getString(Keys.WEB_PATH));
+
+ var outputPath = Paths.get(root, path);
+ var directoryPath = outputPath.getParent();
+ if (directoryPath != null) {
+ Files.createDirectories(directoryPath);
+ }
+
+ try (var input = new FileInputStream(inputFile); var output = new FileOutputStream(outputPath.toFile())) {
+ input.transferTo(output);
+ }
+ return Response.ok().build();
+ }
+
}