Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
pse-trapp-public
IntentFinder
Commits
04a13da9
Commit
04a13da9
authored
May 16, 2021
by
Chiraz Boukadida
Browse files
#31
Implementation Endpoint Hochladen einer DOCX-FAQ-Datei mit Änderungen
parent
3649239c
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/ktor-server/src/main/kotlin/de/h_da/fbi/smebt/intentfinder/client/Application.kt
View file @
04a13da9
...
...
@@ -29,11 +29,38 @@ suspend fun main() {
println
(
response
.
readText
())
println
(
response
.
status
)
val
fileName
=
"Dok1.docx"
val
PutClient
=
HttpClient
(
CIO
)
val
putResponse
:
HttpResponse
=
PutClient
.
submitFormWithBinaryData
(
url
=
"http://localhost:8080/file?filename=Dok1.docx/"
,
// url = "http://localhost:8080/file/{fileName}/",
// url = "http://localhost:8080/file/{$fileName}/",
// url = "http://localhost:8080/file/$fileName/",
//url = "http://localhost:8080/file/Dok1.docx/",
formData
=
formData
{
append
(
"description"
,
"docx Document"
)
append
(
"fileName"
,
File
(
"uploads/Dok1.docx"
).
readBytes
(),
Headers
.
build
{
append
(
HttpHeaders
.
ContentType
,
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
)
append
(
HttpHeaders
.
ContentDisposition
,
"filename=Dok1.docx"
)
})
}
)
println
(
putResponse
.
readText
())
println
(
putResponse
.
status
)
try
{
val
reader
=
DocxReader
(
"uploads/Dok.docx"
)
val
fileContent
=
reader
.
readFile
()
println
(
fileContent
)
val
reader1
=
DocxReader
(
"uploads/Dok1.docx"
)
val
fileContent1
=
reader1
.
readFile
()
println
(
fileContent1
)
}
catch
(
exception
:
Exception
)
{
print
(
exception
.
message
)
}
...
...
src/ktor-server/src/main/kotlin/de/h_da/fbi/smebt/intentfinder/server/Application.kt
View file @
04a13da9
package
de.h_da.fbi.smebt.intentfinder.server
import
de.h_da.fbi.smebt.intentfinder.server.nlp.PythonBridge
import
de.h_da.fbi.smebt.intentfinder.server.sources.DocxReader
import
io.ktor.application.*
import
io.ktor.features.*
import
io.ktor.http.*
...
...
@@ -60,6 +61,38 @@ fun Application.module(testing: Boolean = false) {
call
.
respondText
(
"$fileDescription is uploaded to 'uploads/$fileName'"
)
}
put
(
"/file/{filename}/{id}"
)
{
val
name
=
call
.
parameters
[
"filename"
].
toString
()
val
file
=
File
(
"uploads/$name "
)
val
multipartData
=
call
.
receiveMultipart
()
if
(!
file
.
exists
())
{
call
.
respond
(
HttpStatusCode
.
NotFound
)
}
else
{
multipartData
.
forEachPart
{
part
->
when
(
part
)
{
is
PartData
.
FormItem
->
{
fileDescription
=
part
.
value
}
is
PartData
.
FileItem
->
{
val
reader
=
DocxReader
(
"uploads/Dok.docx"
)
if
(!
reader
.
readFile
().
equals
(
part
.
streamProvider
().
toString
()))
{
fileName
=
part
.
originalFileName
as
String
var
fileBytes
=
part
.
streamProvider
().
readBytes
()
File
(
"uploads/$fileName"
).
writeBytes
(
fileBytes
)
}
else
{
println
(
"no change detected"
)
}
}
}
}
}
val
reader
=
DocxReader
(
"uploads/Dok.docx"
)
val
fileContent
=
reader
.
readFile
()
call
.
respondText
(
"$fileDescription is uploaded to 'uploads/$fileName and contains: \n $fileContent' "
)
}
}
registerUploadRoutes
()
}
src/ktor-server/src/test/Upload.http
View file @
04a13da9
...
...
@@ -13,4 +13,19 @@ Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.doc
< ./Dok.docx
--FileBoundary--
###
\ No newline at end of file
###
PUT POST http://0.0.0.0:8080/file/Dok1.docx/
Content-Type: multipart/form-data;boundary=FileBoundary
--FileBoundary
Content-Disposition: form-data; name="description"
Content-Type: text/plain
docx Document
--FileBoundary
Content-Disposition: form-data; name="Dok"; filename="Dok1.docx"
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
< ./Dok1.docx
--FileBoundary--
\ No newline at end of file
src/ktor-server/uploads/Dok1.docx
0 → 100644
View file @
04a13da9
File added
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