mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-30 04:01:02 +00:00
compress to JPEG before uploading
This commit is contained in:
parent
627173989e
commit
99dc57a023
2 changed files with 3 additions and 3 deletions
|
@ -141,7 +141,7 @@ public class Client: ObservableObject, Equatable {
|
|||
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||
let httpBody = NSMutableData()
|
||||
httpBody.append("--\(boundary)\r\n".data(using: .utf8)!)
|
||||
httpBody.append("Content-Disposition: form-data; name=\"file\"; filename=\"file.png\"\r\n".data(using: .utf8)!)
|
||||
httpBody.append("Content-Disposition: form-data; name=\"file\"; filename=\"file.jpg\"\r\n".data(using: .utf8)!)
|
||||
httpBody.append("Content-Type: \(mimeType)\r\n".data(using: .utf8)!)
|
||||
httpBody.append("\r\n".data(using: .utf8)!)
|
||||
httpBody.append(data)
|
||||
|
|
|
@ -158,7 +158,7 @@ public class StatusEditorViewModel: ObservableObject {
|
|||
for (index, media) in mediasCopy.enumerated() {
|
||||
do {
|
||||
if !Task.isCancelled,
|
||||
let data = media.image?.pngData(),
|
||||
let data = media.image?.jpegData(compressionQuality: 0.90),
|
||||
let uploadedMedia = try await uploadMedia(data: data) {
|
||||
mediasImages[index] = .init(image: nil, mediaAttachement: uploadedMedia, error: nil)
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ public class StatusEditorViewModel: ObservableObject {
|
|||
private func uploadMedia(data: Data) async throws -> MediaAttachement? {
|
||||
guard let client else { return nil }
|
||||
do {
|
||||
return try await client.mediaUpload(mimeType: "image/png", data: data)
|
||||
return try await client.mediaUpload(mimeType: "image/jpeg", data: data)
|
||||
} catch {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue