我正在使用 Retrofit 2.5.0 将图像上传到 NodeJS 服务器,
当我尝试上传图像时出现错误。
当我记录请求时,它不会读取完整文件并给出 EOF 异常。
我正在使用 MultiPart 上传,这是我的代码 fragment
RequestBody requestFile =
RequestBody.create(MediaType.parse("image/jpg"), file);
MultipartBody.Part body =
MultipartBody.Part.createFormData("image", file.getName(), requestFile);
// add another part within the multipart request
RequestBody fullName =
RequestBody.create(
MediaType.parse("multipart/form-data"), image.getDescription());
这是 okHttp 日志:
--------- beginning of main
10-30 14:25:45.330 11236-11402/com.project.peoject D/OkHttp: �Dw�m�1��l��n�D�RXZX�1[)$M��l�`���7Q���n�ӟ̊e��L�،����=�k����*a�~�g��=�U�ɨ@<�x���/���>� ���R���@���z�;c�?��Zʖ7��ۮ�0��*r�����#ך������3��J��F{���v� ����Kk�̌�$|�|
read: unexpected EOF!
最佳答案
“阅读:意外的 EOF!”面对大量日志时出现Logcat错误。 您可以通过运行此行来扩大缓冲区大小:
adb logcat -G 1m
缓冲区的默认大小为 256k,通过运行上面的行,您会将其增加到 1MB。
关于java - 使用 Retrofit 2 将图像从图库/相机上传到服务器(okhttp 问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56121923/