简体   繁体   中英

Issue uploading files to a web server

If the file name contains Turkish characters (ş, ı, ü, ü, ö, ğ), the file is not uploaded to the web server. The upload to web server is done on php page. There is no problem there. It uploads file names that do not contain Turkish characters (English letters). How do I solve this problem?

    private String uploadFile() 
    {
        String responseString = null;

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(Config.FILE_UPLOAD_URL);
        try 
        {
            AndroidMultiPartEntity entity = new AndroidMultiPartEntity(new ProgressListener() {
            @Override
            public void transferred(long num) {
                publishProgress((int) ((num / (float) totalSize) * 100));
            } });

            File kaynakDosya = new File(filePath);

            entity.addPart("dosya", new FileBody(kaynakDosya));
            entity.addPart("islem", new StringBody(GlobalVeri.IslemFotoVideoDosya));

            totalSize = entity.getContentLength();
            httppost.setEntity(entity);

            HttpResponse response = httpclient.execute(httppost);
            HttpEntity r_entity = response.getEntity();

            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == 200) {
                responseString = EntityUtils.toString(r_entity);
            } else {
                responseString = "Bir hata oluştu! Http Durum Kodu: " + statusCode;
            }           
        } 
        catch (ClientProtocolException e) {
            responseString = e.toString();
        } 
        catch (IOException e) {
            responseString = e.toString();
        }
        return responseString;
    }

I believe you are missing UTF-8 encoding. As StringBody , put the text that you're passing as the first argument with those special characters, and make sure you say it's utf-8 in the 2nd argument. Replace

entity.addPart("islem", new StringBody(GlobalVeri.IslemFotoVideoDosya));

with

entity.addPart("islem", new StringBody(GlobalVeri.IslemFotoVideoDosya, Charset.forName(HTTP.UTF_8))));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM