我正在尝试发送转换后的文件(Base64字符串)作为POST中的参数,文件大约有8MB,但发送大约需要4分钟。有没有加速的方法?
接口:
@FormUrlEncoded
@POST("upload")
Call<Upload> upload(@Field("CONTENT") String content);改装实例:
public class RetrofitClientInstance {
private static Retrofit retrofit;
private static OkHttpClient client;
public static Retrofit getRetrofitInstance(String url) {
    if (retrofit == null && !url.isEmpty()) {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        client = new OkHttpClient.Builder()
                .addInterceptor(interceptor)
                .build();
        retrofit = new retrofit2.Retrofit.Builder()
                .baseUrl(url)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
}}呼叫:
 private void upload(){
    Api api = RetrofitClientInstance.getRetrofitInstance(SharedUtils.SERVER_URL).create(Api.class);
    Call<Upload> request = api.upload(getBase64FromFile());
    request.enqueue(new Callback<Upload>() {
        @Override
        public void onResponse(Call<Upload> call, Response<Upload> response) {
        }
        @Override
        public void onFailure(Call<Upload> call, Throwable t) {
        }
    });
}发布于 2018-09-21 17:40:41
尝试在上传之前压缩你的文件或图像,因为这将花费太多的时间
https://stackoverflow.com/questions/52440805
复制相似问题