diff options
author | Anton Tananaev <anton@traccar.org> | 2024-04-04 07:54:07 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-04-04 07:54:07 -0700 |
commit | 1c29f3a604fe13c8a337935a1a1ad966b4b62d5b (patch) | |
tree | 88c4b918f8642cea7ef6a70aeeb79d5a940d31d4 /src/main/java/org/traccar | |
parent | 3fbdcd81566bc72e319ec05c77cf8a4120b87b8f (diff) | |
download | trackermap-server-1c29f3a604fe13c8a337935a1a1ad966b4b62d5b.tar.gz trackermap-server-1c29f3a604fe13c8a337935a1a1ad966b4b62d5b.tar.bz2 trackermap-server-1c29f3a604fe13c8a337935a1a1ad966b4b62d5b.zip |
Handle explicit image types
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r-- | src/main/java/org/traccar/api/resource/DeviceResource.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/api/resource/DeviceResource.java b/src/main/java/org/traccar/api/resource/DeviceResource.java index 89bba7237..d7236fe2a 100644 --- a/src/main/java/org/traccar/api/resource/DeviceResource.java +++ b/src/main/java/org/traccar/api/resource/DeviceResource.java @@ -172,6 +172,23 @@ public class DeviceResource extends BaseObjectResource<Device> { return Response.noContent().build(); } + private String imageExtension(String type) { + switch (type) { + case "image/jpeg": + return ".jpg"; + case "image/png": + return ".png"; + case "image/gif": + return ".gif"; + case "image/webp": + return ".webp"; + case "image/svg+xml": + return ".svg"; + default: + throw new IllegalArgumentException("Unsupported image type"); + } + } + @Path("{id}/image") @POST @Consumes("image/*") @@ -186,7 +203,7 @@ public class DeviceResource extends BaseObjectResource<Device> { new Condition.Permission(User.class, getUserId(), Device.class)))); if (device != null) { String name = "device"; - String extension = type.substring("image/".length()); + String extension = imageExtension(type); try (var input = new FileInputStream(file); var output = mediaManager.createFileStream(device.getUniqueId(), name, extension)) { input.transferTo(output); |