Fast-Android-Networking
Fast-Android-Networking copied to clipboard
Uploading file Not Working when file name contains Arabic numbers or characters
Uploading file Not Working when file name contains Arabic numbers or characters. Please help me this is urgent!
fun attachMessageFile(attachRequest: AttachRequest, upload: UploadProgressListener?): Single<AttachMessageResponse> {
return Rx2AndroidNetworking.upload(ApiEndPoints.ATTACH_FILE)
.addHeaders(apiHeader)
.addMultipartFile("file", attachRequest.file, ";charset=utf-8")
.setContentType(";charset=utf-8")
.addMultipartParameter("duration", attachRequest.duration)
.addMultipartParameter("chat_id", attachRequest.chatId.toString())
.addMultipartParameter("type", attachRequest.type.toString())
.setPriority(Priority.HIGH)
.build()
.setUploadProgressListener(upload)
.getParseSingle(object : TypeToken<AttachMessageResponse>() {})
}
I'm one of your course Advanced Android Development members, I really enjoy it and please help me with this. We have the same problem as described our file name is "photo_Û²Û²Û².jpg" Please help us with solving this.
I will look into it. Can you please slack me the more details so that I can try debugging it.
I try to upload image and the image name is تيست.jpg Image path : "/storage/emulated/0/IELTS/تيست.jpg"
If i try to upload image with english name it's uploading success but if i try to upload any image contains Arabic numbers or characters the image dos't upload, and our server support unicode.
fun attachMessageFile(attachRequest: AttachRequest, upload: UploadProgressListener?): Single<AttachMessageResponse> {
return Rx2AndroidNetworking.upload(ApiEndPoints.ATTACH_FILE)
.addHeaders(apiHeader)
.addMultipartFile("file", attachRequest.file)
.addMultipartParameter("duration", attachRequest.duration)
.addMultipartParameter("chat_id", attachRequest.chatId.toString())
.addMultipartParameter("type", attachRequest.type.toString())
.setPriority(Priority.HIGH)
.build()
.setUploadProgressListener(upload)
.getParseSingle(object : TypeToken<AttachMessageResponse>() {})
}
class ApiHeader {
@SerializedName("App-Version")
var appVersion = "7"
@SerializedName("Accept")
var accept = "application/json"
@SerializedName("Device-Type")
var deviceType = "a"
@SerializedName("Authorization")
var authorization: String = ""
@SerializedName("Content-Type")
var type: String = "application/json"
@SerializedName("player-id")
var playerId: String = ""
@SerializedName("locale")
var locale: String = LanguageSetting.getLanguage(BaseApplication.getInstance()).language
@SerializedName("Freshchat-Restore-Id")
var restoreId: String = ""
@SerializedName("Country")
var country: String = BaseApplication.getInstance().getCountryRegionFromPhone()
@SerializedName("Currency-Country")
var curency: String = "US"
@SerializedName("apn-token")
var apnToken: String = ""
}
I added also contentType "application/json ;charset=utf-8" and it doesn't working
@amitshekhariitbhu You need any another details?
Are you able to read this file and use it in Android with that name?
@amitshekhariitbhu Yes I can read any file with any Arabic name
@amitshekhariitbhu, we hope to get your update on this one ASAP, it too many people complaining from the crashes happens due to this. Thank you.
@amitshekhariitbhu I have the same behavior with cyrilic file name
@mwaked @amitshekhariitbhu
In my case App catch this exception:
2020-07-29 12:26:19.093 27295-27565/com.ispring.islearn.debug E/BasicApi$Companion: com.androidnetworking.error.ANError: java.lang.IllegalStateException: Multipart body must have at least one part.
at com.androidnetworking.internal.SynchronousCall.executeUploadRequest(SynchronousCall.java:138)
at com.androidnetworking.internal.SynchronousCall.execute(SynchronousCall.java:53)
at com.androidnetworking.common.ANRequest.executeForString(ANRequest.java:345)
...
Caused by: java.lang.IllegalStateException: Multipart body must have at least one part.
at okhttp3.MultipartBody$Builder.build(MultipartBody.java:341)
at com.androidnetworking.common.ANRequest.getMultiPartRequestBody(ANRequest.java:886)
at com.androidnetworking.internal.InternalNetworking.performUploadRequest(InternalNetworking.java:227)
at com.androidnetworking.internal.SynchronousCall.executeUploadRequest(SynchronousCall.java:115)
at com.androidnetworking.internal.SynchronousCall.execute(SynchronousCall.java:53)Â
at com.androidnetworking.common.ANRequest.executeForString(ANRequest.java:345)Â
In my case before send file app says server file name and file size to get upload_url. My workaround is use temp file with latin name. Copy source file to temp then upload temp file.
Also had this problem, fixed it and sent a pull request #563 before it is committed to the main branch you can use this:
- Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
-
Add the dependency
implementation 'com.github.MansourM:Fast-Android-Networking:1.0.3' -
add encoding to your file uploads like this
.addMultipartFile(KEY, FILE, CONTENT_TYPE, "utf-8")