Removing file transform function
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.actions
|
package com.vitorpamplona.amethyst.ui.actions
|
||||||
|
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.content.Context
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.OpenableColumns
|
import android.provider.OpenableColumns
|
||||||
import android.util.Log
|
|
||||||
import android.webkit.MimeTypeMap
|
import android.webkit.MimeTypeMap
|
||||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import com.vitorpamplona.amethyst.BuildConfig
|
import com.vitorpamplona.amethyst.BuildConfig
|
||||||
@@ -12,8 +10,6 @@ import okhttp3.*
|
|||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
import okio.BufferedSink
|
import okio.BufferedSink
|
||||||
import okio.source
|
import okio.source
|
||||||
import java.io.File
|
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
@@ -124,38 +120,6 @@ object ImageUploader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRealPathFromURI(uri: Uri, context: Context): String? {
|
|
||||||
val returnCursor = context.contentResolver.query(uri, null, null, null, null)
|
|
||||||
val nameIndex = returnCursor!!.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
|
||||||
returnCursor.moveToFirst()
|
|
||||||
val name = returnCursor.getString(nameIndex)
|
|
||||||
val file = File(context.filesDir, name)
|
|
||||||
try {
|
|
||||||
val inputStream: InputStream? = context.contentResolver.openInputStream(uri)
|
|
||||||
val outputStream = FileOutputStream(file)
|
|
||||||
var read = 0
|
|
||||||
val maxBufferSize = 1 * 1024 * 1024
|
|
||||||
val bytesAvailable: Int = inputStream?.available() ?: 0
|
|
||||||
val bufferSize = Math.min(bytesAvailable, maxBufferSize)
|
|
||||||
val buffers = ByteArray(bufferSize)
|
|
||||||
while (inputStream?.read(buffers).also {
|
|
||||||
if (it != null) {
|
|
||||||
read = it
|
|
||||||
}
|
|
||||||
} != -1
|
|
||||||
) {
|
|
||||||
outputStream.write(buffers, 0, read)
|
|
||||||
}
|
|
||||||
Log.e("File Size", "Size " + file.length())
|
|
||||||
inputStream?.close()
|
|
||||||
outputStream.close()
|
|
||||||
Log.e("File Path", "Path " + file.path)
|
|
||||||
} catch (e: java.lang.Exception) {
|
|
||||||
Log.e("Exception", e.message!!)
|
|
||||||
}
|
|
||||||
return file.path
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class FileServer {
|
abstract class FileServer {
|
||||||
abstract fun postUrl(contentType: String?): String
|
abstract fun postUrl(contentType: String?): String
|
||||||
abstract fun parseUrlFromSucess(body: String): String?
|
abstract fun parseUrlFromSucess(body: String): String?
|
||||||
|
|||||||
Reference in New Issue
Block a user