当前位置: 首页 > 知识库问答 >
问题:

试图上传图片,但得到这个错误Android应用程序

羊舌诚
2023-03-14

Im使用okhttp 2.5.0,Im获取一张pic,然后将其转换为base 64格式,然后将其作为post变量发送到服务器,然后将其解码回jpg格式并保存到服务器....当我使用像1兆像素(0.5MB)的小图像时,它可以完美地工作······但是当我增加分辨率时,这个异常发生了...

09-10 23:29:47.673  25742-27156/in.definexit.chemapp W/System.err﹕ java.net.SocketTimeoutException: timeout
09-10 23:29:47.676  25742-27156/in.definexit.chemapp W/System.err﹕ at okio.Okio$3.newTimeoutException(Okio.java:207)
09-10 23:29:47.676  25742-27156/in.definexit.chemapp W/System.err﹕ at okio.AsyncTimeout.exit(AsyncTimeout.java:261)
09-10 23:29:47.677  25742-27156/in.definexit.chemapp W/System.err﹕ at okio.AsyncTimeout$1.write(AsyncTimeout.java:158)
09-10 23:29:47.677  25742-27156/in.definexit.chemapp W/System.err﹕ at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
09-10 23:29:47.677  25742-27156/in.definexit.chemapp W/System.err﹕ at okio.RealBufferedSink.write(RealBufferedSink.java:46)
09-10 23:29:47.677  25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.internal.http.HttpConnection$FixedLengthSink.write(HttpConnection.java:302)
09-10 23:29:47.677  25742-27156/in.definexit.chemapp W/System.err﹕ at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
09-10 23:29:47.677  25742-27156/in.definexit.chemapp W/System.err﹕ at okio.RealBufferedSink.write(RealBufferedSink.java:96)
09-10 23:29:47.679  25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.RequestBody$2.writeTo(RequestBody.java:96)
09-10 23:29:47.679  25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.MultipartBuilder$MultipartRequestBody.writeOrCountBytes(MultipartBuilder.java:277)
09-10 23:29:47.682  25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.MultipartBuilder$MultipartRequestBody.writeTo(MultipartBuilder.java:297)
09-10 23:29:47.682  25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:887)
09-10 23:29:47.682  25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:749)
09-10 23:29:47.682  25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.Call.getResponse(Call.java:268)
09-10 23:29:47.684  25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
09-10 23:29:47.685  25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
09-10 23:29:47.686  25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.Call.execute(Call.java:79)
09-10 23:29:47.686  25742-27156/in.definexit.chemapp W/System.err﹕ at in.definexit.chemapp.BGServerScripts.doInBackground(BGServerScripts.java:112)
09-10 23:29:47.686  25742-27156/in.definexit.chemapp W/System.err﹕ at in.definexit.chemapp.BGServerScripts.doInBackground(BGServerScripts.java:27)
09-10 23:29:47.686  25742-27156/in.definexit.chemapp W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:292)
09-10 23:29:47.686  25742-27156/in.definexit.chemapp W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
09-10 23:29:47.687  25742-27156/in.definexit.chemapp W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
09-10 23:29:47.687  25742-27156/in.definexit.chemapp W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-10 23:29:47.687  25742-27156/in.definexit.chemapp W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
09-10 23:29:47.687  25742-27156/in.definexit.chemapp W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
09-10 23:29:47.687  25742-27156/in.definexit.chemapp W/System.err﹕ Caused by: java.net.SocketException: Socket closed
09-10 23:29:47.690  25742-27156/in.definexit.chemapp W/System.err﹕ at libcore.io.Posix.sendtoBytes(Native Method)
09-10 23:29:47.690  25742-27156/in.definexit.chemapp W/System.err﹕ at libcore.io.Posix.sendto(Posix.java:206)
09-10 23:29:47.690  25742-27156/in.definexit.chemapp W/System.err﹕ at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:278)
09-10 23:29:47.691  25742-27156/in.definexit.chemapp W/System.err﹕ at libcore.io.IoBridge.sendto(IoBridge.java:513)
09-10 23:29:47.691  25742-27156/in.definexit.chemapp W/System.err﹕ at java.net.PlainSocketImpl.write(PlainSocketImpl.java:504)
09-10 23:29:47.691  25742-27156/in.definexit.chemapp W/System.err﹕ at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:37)
09-10 23:29:47.691  25742-27156/in.definexit.chemapp W/System.err﹕ at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:266)
09-10 23:29:47.691  25742-27156/in.definexit.chemapp W/System.err﹕ at okio.Okio$1.write(Okio.java:80)
09-10 23:29:47.691  25742-27156/in.definexit.chemapp W/System.err﹕ at okio.AsyncTimeout$1.write(AsyncTimeout.java:155)
09-10 23:29:47.692  25742-27156/in.definexit.chemapp W/System.err﹕ ... 22 more

共有1个答案

长孙波鸿
2023-03-14

您正在使用Base64发送图像。Base64基本上是二进制数据的ASCII表示,它允许我们将数据嵌入到文本流中,比如JSON,但是还应该注意,在使用它时,数据的大小会增加。您之所以获得SocketTimeoutException,是因为数据很大,上传调用没有在超时前完成,或者网络速度慢,图像没有在指定时间内上传。

使用multipart/form-data是HTTP请求中传输二进制文件的标准方式。使用这种方法总是更好,除非这样做有一些限制。

 类似资料:
  • ---exec-maven-plugin:1.2.1:exec(default-cli)@bootsample--- 启动ApplicationContext时出错。若要显示自动配置报告,请在启用“debug”的情况下重新运行应用程序。2018-06-07 09:09:38.463错误10208---[main]O.S.B.D.LoggingFailureAnalysisReporter: 应用程

  • java.lang.IllegalStateException:未能加载ApplicationContext 原因:org . spring framework . beans . factory . unsatisfieddependencyexception:创建在URL[jar:file:/C:/Users/MDI vya/. m2/repository/io/spring fox/spri

  • 我已经安装了最新的构建工具;29.0.2.还是说没有安装构建工具 C:\用户\用户\下载\android-dio-\android-dios\bin\runnerw.exeC:\用户\用户\AppData\漫游\npm\cordova.cmd运行android检查JavaJDK和Android SDK版本ANDROID_SDK_ROOT=未定义(推荐设置)ANDROID_HOME=C:\用户\用户

  • 下面是我保存在两个变量中的两个数据: 其代码: 我认为这与index_col=0参数有关。但我不知道在不保存它的情况下修复它,这并不重要,但我不得不这样做是一种烦恼。

  • 我需要将Flickr与Android集成。我完成了认证。我需要上传图片到flickr,但我不知道如何做同样。我参考文档:http://www.flickr.com/services/api/upload.api.html。有人能帮我吗

  • 为了排除可能的其他问题,我可以使用update.json方法成功地将状态更新发布到Twitter。 我还尝试使用client.addfile方法和Fiddler,看起来一切都就绪了。但我不断得到的错误信息是