发送带有改造 2 的文件,其文件名包含波斯字符

Azi*_*chi 5 android multipart retrofit retrofit2

我正在发送multipart带有改造的请求,它工作正常。但是当我的文件名包含波斯字符时,我的应用程序崩溃并出现此错误:

java.lang.IllegalArgumentException:内容处置值中 35 处出现意外字符 0x62f:表单数据;名称=“照片”;文件名="??????.jpg"

这就是我发送多部分请求的方式:

    File imageFile = new File(imagePath);

    ProgressRequestBody fileBody = new ProgressRequestBody(imageFile, this);
    MultipartBody.Part filePart = MultipartBody.Part.createFormData("photo", imageFile.getName(), fileBody);

    RetroInterface retroInterface = RetrofitClientInstance.getRetrofitInstance().create(RetroInterface.class);
    Call<SendFileResponse> call = retroInterface.sendPhoto(token, myHashmap, filePart);
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?!

小智 0

只是一个建议,但作为解决方法,您可以尝试将文件重命名为文件名的 id(时间戳/其他任何内容),并添加一个名称字段,该字段将包含实际名称(如果文件...)

public class Object {
  private String filename;
  private File actualFile;
}
Run Code Online (Sandbox Code Playgroud)

这样,以后检索时您仍然可以引用所需的文件。