Fast-Android-Networking icon indicating copy to clipboard operation
Fast-Android-Networking copied to clipboard

Uploading file Not Working when file name contains Arabic numbers or characters

Open mwaked opened this issue 5 years ago • 10 comments

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>() {})
    }

mwaked avatar Mar 25 '20 11:03 mwaked

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.

marab2 avatar Mar 26 '20 06:03 marab2

I will look into it. Can you please slack me the more details so that I can try debugging it.

amitshekhariitbhu avatar Mar 26 '20 07:03 amitshekhariitbhu

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

mwaked avatar Mar 26 '20 07:03 mwaked

@amitshekhariitbhu You need any another details?

mwaked avatar Mar 26 '20 11:03 mwaked

Are you able to read this file and use it in Android with that name?

amitshekhariitbhu avatar Mar 27 '20 10:03 amitshekhariitbhu

@amitshekhariitbhu Yes I can read any file with any Arabic name

mwaked avatar Mar 27 '20 10:03 mwaked

@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.

marab2 avatar Mar 28 '20 17:03 marab2

@amitshekhariitbhu I have the same behavior with cyrilic file name

iandreyshev avatar Jul 29 '20 06:07 iandreyshev

@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.

iandreyshev avatar Jul 29 '20 09:07 iandreyshev

Also had this problem, fixed it and sent a pull request #563 before it is committed to the main branch you can use this:

  1. Add it in your root build.gradle at the end of repositories:
	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
  1. Add the dependency implementation 'com.github.MansourM:Fast-Android-Networking:1.0.3'

  2. add encoding to your file uploads like this .addMultipartFile(KEY, FILE, CONTENT_TYPE, "utf-8")

MansourM avatar Jul 02 '21 22:07 MansourM