@@ -12,9 +12,16 @@ import com.abedelazizshe.lightcompressorlibrary.VideoQuality
12
12
import com.abedelazizshe.lightcompressorlibrary.config.Configuration
13
13
import com.abedelazizshe.lightcompressorlibrary.config.SaveLocation
14
14
import com.abedelazizshe.lightcompressorlibrary.config.SharedStorageConfiguration
15
+ import com.record.common.util.getVideoFrameAt1Sec
15
16
import kotlinx.coroutines.CoroutineScope
16
17
import kotlinx.coroutines.Dispatchers
17
18
import kotlinx.coroutines.launch
19
+ import okhttp3.MediaType.Companion.toMediaTypeOrNull
20
+ import okhttp3.OkHttpClient
21
+ import okhttp3.Request
22
+ import okhttp3.RequestBody
23
+ import java.io.File
24
+ import java.io.IOException
18
25
19
26
fun getAllVideos (
20
27
loadSize : Int ,
@@ -93,7 +100,59 @@ fun getVideoDuration(context: Context, uri: Uri): Long {
93
100
retriever.release()
94
101
}
95
102
}
103
+ fun uploadFileToS3PresignedUrl (presignedUrl : String , file : File , callback : (Boolean , String ) -> Unit ) {
104
+ val client = OkHttpClient ()
105
+ val mediaType = " application/octet-stream" .toMediaTypeOrNull()
106
+ val requestBody = RequestBody .create(mediaType, file)
96
107
108
+ val request = Request .Builder ()
109
+ .url(presignedUrl)
110
+ .put(requestBody)
111
+ .build()
112
+ client.newCall(request).enqueue(
113
+ object : okhttp3.Callback {
114
+ override fun onFailure (call : okhttp3.Call , e : IOException ) {
115
+ callback(false , " Upload failed: ${e.message} " )
116
+ }
117
+
118
+ override fun onResponse (call : okhttp3.Call , response : okhttp3.Response ) {
119
+ if (response.isSuccessful) {
120
+ callback(true , " ${response.request.url} " )
121
+ } else {
122
+ callback(false , " Upload failed: ${response.message} " )
123
+ }
124
+ }
125
+ },
126
+ )
127
+ }
128
+ fun uploadFileToS3ThumbnailPresignedUrl (context : Context , presignedUrl : String , file : File , callback : (Boolean , String ) -> Unit ) {
129
+ val videoPath = file.absolutePath
130
+ val outputImagePath = File (context.cacheDir, file.name)
131
+ getVideoFrameAt1Sec(videoPath, outputImagePath.absolutePath)
132
+ val client = OkHttpClient ()
133
+ val mediaType = " application/octet-stream" .toMediaTypeOrNull()
134
+ val requestBody = RequestBody .create(mediaType, outputImagePath)
135
+
136
+ val request = Request .Builder ()
137
+ .url(presignedUrl)
138
+ .put(requestBody)
139
+ .build()
140
+ client.newCall(request).enqueue(
141
+ object : okhttp3.Callback {
142
+ override fun onFailure (call : okhttp3.Call , e : IOException ) {
143
+ callback(false , " Upload failed: ${e.message} " )
144
+ }
145
+
146
+ override fun onResponse (call : okhttp3.Call , response : okhttp3.Response ) {
147
+ if (response.isSuccessful) {
148
+ callback(true , " ${response.request.url} " )
149
+ } else {
150
+ callback(false , " Upload failed: ${response.message} " )
151
+ }
152
+ }
153
+ },
154
+ )
155
+ }
97
156
fun formatDuration (durationMillis : Long ): String {
98
157
val minutes = (durationMillis / 1000 ) / 60
99
158
val seconds = (durationMillis / 1000 ) % 60
0 commit comments