package com.framework.app.tools

import android.content.Context
import com.framework.app.http.FileInfo
import com.framework.mvvm.model.data.SuccessResponse
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.File
import java.io.FileInputStream

/**
 * 读取文件，返回字节数组
 */
fun File.toBytes(): ByteArray {
    val fis = FileInputStream(this)
    return fis.readBytes()
}

fun File.toRequestBody(
    mediaType: String = "application/json;charset=utf-8"
): RequestBody {
    val bytes = this.toBytes()
    return bytes.toRequestBody(mediaType.toMediaType())
}