Add mime type info to file and image uploads.

This commit is contained in:
2018-12-20 20:13:09 -08:00
parent 03c472a78d
commit c483e6ac6c
3 changed files with 19 additions and 17 deletions

View File

@@ -40,13 +40,13 @@ sync apiUrl token nextBatch = request
, tracker = Nothing
}
uploadMediaFile : ApiUrl -> ApiToken -> (Result Http.Error String -> Msg) -> File -> Cmd Msg
uploadMediaFile : ApiUrl -> ApiToken -> (String -> Result Http.Error String -> Msg) -> File -> Cmd Msg
uploadMediaFile apiUrl token msg file = request
{ method = "POST"
, headers = authenticatedHeaders token
, url = Builder.crossOrigin (fullMediaUrl apiUrl) [ "upload" ] [ Builder.string "filename" (name file) ]
, body = fileBody file
, expect = expectJson msg <| Json.Decode.field "content_uri" Json.Decode.string
, expect = expectJson (msg <| mime file) <| Json.Decode.field "content_uri" Json.Decode.string
, timeout = Nothing
, tracker = Nothing
}
@@ -82,18 +82,20 @@ sendTextMessage apiUrl token transactionId room message = sendMessage apiUrl tok
, ("body", string message)
]
sendImageMessage : ApiUrl -> ApiToken -> Int -> RoomId -> String -> Cmd Msg
sendImageMessage apiUrl token transactionId room message = sendMessage apiUrl token transactionId room SendImageResponse
sendImageMessage : ApiUrl -> ApiToken -> Int -> RoomId -> String -> String -> Cmd Msg
sendImageMessage apiUrl token transactionId room mime message = sendMessage apiUrl token transactionId room SendImageResponse
[ ("msgtype", string "m.image")
, ("body", string "Image")
, ("url", string message)
, ("info", object [ ("mimetype", string mime) ])
]
sendFileMessage : ApiUrl -> ApiToken -> Int -> RoomId -> String -> Cmd Msg
sendFileMessage apiUrl token transactionId room message = sendMessage apiUrl token transactionId room SendFileResponse
sendFileMessage : ApiUrl -> ApiToken -> Int -> RoomId -> String -> String -> Cmd Msg
sendFileMessage apiUrl token transactionId room mime message = sendMessage apiUrl token transactionId room SendFileResponse
[ ("msgtype", string "m.file")
, ("body", string "File")
, ("url", string message)
, ("info", object [ ("mimetype", string mime) ])
]
login : ApiUrl -> Username -> Password -> Cmd Msg

View File

@@ -57,8 +57,8 @@ type Msg =
| SendFiles RoomId
| ImagesSelected RoomId File (List File)
| FilesSelected RoomId File (List File)
| ImageUploadComplete RoomId (Result Http.Error String)
| FileUploadComplete RoomId (Result Http.Error String)
| ImageUploadComplete RoomId String (Result Http.Error String)
| FileUploadComplete RoomId String (Result Http.Error String)
| SendImageResponse (Result Http.Error ())
| SendFileResponse (Result Http.Error ())