Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GeoFlyApi
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GeoFly
GeoFlyApi
Commits
668c47af
Commit
668c47af
authored
Aug 02, 2025
by
gdj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
航飞任务图片上传,移动文件到org目录下。
parent
4f655e37
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
3 deletions
+62
-3
sample/src/main/java/com/dji/sample/media/service/impl/MediaServiceImpl.java
+58
-3
sample/src/main/resources/application.yml
+4
-0
No files found.
sample/src/main/java/com/dji/sample/media/service/impl/MediaServiceImpl.java
View file @
668c47af
...
...
@@ -12,6 +12,7 @@ import com.dji.sample.media.model.MediaFileDTO;
import
com.dji.sample.media.service.IFileService
;
import
com.dji.sample.media.service.IMediaRedisService
;
import
com.dji.sample.media.service.IMediaService
;
import
com.dji.sample.wayline.model.dto.WaylineJobDTO
;
import
com.dji.sample.wayline.service.IWaylineJobService
;
import
com.dji.sdk.cloudapi.media.*
;
import
com.dji.sdk.cloudapi.media.api.AbstractMediaService
;
...
...
@@ -19,12 +20,19 @@ import com.dji.sdk.mqtt.MqttReply;
import
com.dji.sdk.mqtt.events.TopicEventsRequest
;
import
com.dji.sdk.mqtt.events.TopicEventsResponse
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.SneakyThrows
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.messaging.MessageHeaders
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
java.io.File
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.StandardCopyOption
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Optional
;
...
...
@@ -60,6 +68,9 @@ public class MediaServiceImpl extends AbstractMediaService implements IMediaServ
@Autowired
private
IMediaRedisService
mediaRedisService
;
@Value
(
"${my.file.base-path}"
)
private
String
basePath
;
@Override
public
Boolean
fastUpload
(
String
workspaceId
,
String
fingerprint
)
{
return
fileService
.
checkExist
(
workspaceId
,
fingerprint
);
...
...
@@ -150,6 +161,18 @@ public class MediaServiceImpl extends AbstractMediaService implements IMediaServ
}
private
Boolean
parseMediaFile
(
FileUploadCallback
callback
,
DeviceDTO
device
)
{
// moveFile path wayline/workspaceId/jobId/fileName -> wayline/worksapceId/orgId/jobId/fileName
// file.path name objectKey
// 查询 任务的orgId
String
orgId
=
""
;
WaylineJobDTO
jobDTO
=
null
;
Optional
<
WaylineJobDTO
>
jobOpt
=
waylineJobService
.
getJobByJobId
(
device
.
getWorkspaceId
(),
callback
.
getFile
().
getExt
().
getFlightId
());
if
(
jobOpt
.
isPresent
())
{
jobDTO
=
jobOpt
.
get
();
orgId
=
jobDTO
.
getOrgId
();
}
MediaUploadCallbackRequest
file
=
convert2callbackRequest
(
callback
.
getFile
());
// Set the drone sn that shoots the media
file
.
getExt
().
setSn
(
device
.
getChildDeviceSn
());
...
...
@@ -157,13 +180,45 @@ public class MediaServiceImpl extends AbstractMediaService implements IMediaServ
// set path
// todo? 是否需要修改?
String
objectKey
=
file
.
getObjectKey
();
file
.
setPath
(
objectKey
.
substring
(
Optional
.
of
(
objectKey
.
indexOf
(
OssConfiguration
.
objectDirPrefix
))
.
filter
(
index
->
index
>
0
).
map
(
index
->
index
++).
orElse
(
0
),
objectKey
.
lastIndexOf
(
"/"
))
+
"/"
+
device
.
getWorkspaceId
());
String
path
=
objectKey
.
substring
(
Optional
.
of
(
objectKey
.
indexOf
(
OssConfiguration
.
objectDirPrefix
))
.
filter
(
index
->
index
>
0
).
map
(
index
->
index
++).
orElse
(
0
),
objectKey
.
lastIndexOf
(
"/"
));
if
(
StringUtils
.
hasText
(
orgId
))
{
String
orgFilePath
=
path
;
// 增加 org路径
path
=
path
.
replace
(
OssConfiguration
.
objectDirPrefix
+
"/"
+
device
.
getWorkspaceId
(),
OssConfiguration
.
objectDirPrefix
+
"/"
+
device
.
getWorkspaceId
()
+
"/"
+
orgId
);
// jobId改成 jobName
if
(
jobDTO
!=
null
)
{
path
=
path
.
replace
(
callback
.
getFile
().
getExt
().
getFlightId
(),
jobDTO
.
getJobName
());
}
String
moveFilePath
=
path
;
// DJI_20250801115516_0033_V.jpeg
// wayline/e3dea0f5-37f2-4d79-ae58-490af3228069/test-8-1-11-52-2025-08-01-11-52-49-9c08/DJI_202508011152_001_test-8-1-11-52-2025-08-01-11-52-49-9c08/DJI_20250801115516_0033_V.jpeg
file
.
setPath
(
path
);
file
.
setObjectKey
(
moveFilePath
);
moveFile
(
orgFilePath
,
moveFilePath
,
callback
.
getFile
().
getName
());
}
else
{
file
.
setPath
(
path
);
}
return
fileService
.
saveFile
(
device
.
getWorkspaceId
(),
file
)
>
0
;
}
@SneakyThrows
public
void
moveFile
(
String
sourceFilePath
,
String
targetFilePath
,
String
fileName
)
{
File
directory
=
new
File
(
basePath
);
if
(!
directory
.
exists
())
{
boolean
created
=
directory
.
mkdirs
();
}
Path
source
=
Paths
.
get
(
basePath
,
OssConfiguration
.
bucket
,
sourceFilePath
,
fileName
);
Path
targetDir
=
Paths
.
get
(
basePath
,
OssConfiguration
.
bucket
,
targetFilePath
);
if
(!
Files
.
exists
(
targetDir
))
{
Files
.
createDirectories
(
targetDir
);
}
Path
target
=
targetDir
.
resolve
(
fileName
);
Files
.
move
(
source
,
target
,
StandardCopyOption
.
REPLACE_EXISTING
);
}
private
void
notifyUploadedCount
(
MediaFileCountDTO
mediaFileCount
,
TopicEventsRequest
<
FileUploadCallback
>
request
,
String
jobId
,
DeviceDTO
dock
)
{
// Do not notify when files that do not belong to the route are uploaded.
if
(
Objects
.
isNull
(
mediaFileCount
))
{
...
...
sample/src/main/resources/application.yml
View file @
668c47af
server
:
port
:
6789
my
:
file
:
base-path
:
/app/filePath
spring
:
main
:
allow-bean-definition-overriding
:
true
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment