aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api/resource
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/api/resource')
-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();
+ }
+
}