abbasalim
دوشنبه 29 اردیبهشت 1393, 12:08 عصر
بنام خدا
سلام
من با کد زیر یه فایل رو آپلود میکنم منتها اگه نام فایل فارسی باشه (حتی عددهاش) تو url به جا نام فایل ؟؟؟ میزاره مثلا میشه
P_��������_������_wy1x pk04.wee.png
اما در فایل های انگلیسی مشکلی ندارم بایدچیکار کنم به نظرتون کلی استک اورفلو رو زیر و رو کردم چیزه خاصی گیرم نیومد:گریه:
URL url = new URL(f_url[0]);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
// Set the size of the transfer stream, in case that the application
// collapses due to small memory, this method is used when we don't
// know the size of the content, we use HTTP request without cache
httpURLConnection.setChunkedStreamingMode(128 * 1024);// 128K
// Set the input and output
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setUseCaches(false);
// Set the HTTP method
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
httpURLConnection.setRequestProperty("Charset", "UTF-8");
httpURLConnection.setRequestProperty("Content-Type",
"multipart/form-data;boundary=" + boundary);
// Get outputstream according to the url connection
DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream ());
// Write the HTTP POST header
dos.writeBytes(twoHyphens + boundary + end);
dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\"; filename=\""
+ f_url[1].substring(f_url[1].lastIndexOf("/") + 1)
+ "\"" + end);
dos.writeBytes(end);
FileInputStream fis = new FileInputStream(f_url[1]);
int bufferSize = 8 * 1024; // The size of the buffer, 8KB.
byte[] buffer = new byte[bufferSize];
int length = 0;
while ((length = fis.read(buffer)) != -1) {
// Write data to DataOutputStream
dos.write(buffer, 0, length);
}
dos.writeBytes(end);
dos.writeBytes(twoHyphens + boundary + twoHyphens + end);
fis.close(); // Close the FileInputStream.
dos.flush(); // Flush the data to DataOutputStream.
// Get the content of the response
InputStream is = httpURLConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is, "utf-8");
BufferedReader br = new BufferedReader(isr, 8 * 1024);
result = br.readLine();
Log.d(DBAdapter.TAG, result);
} catch (Exception e) {
e.printStackTrace();
}
سلام
من با کد زیر یه فایل رو آپلود میکنم منتها اگه نام فایل فارسی باشه (حتی عددهاش) تو url به جا نام فایل ؟؟؟ میزاره مثلا میشه
P_��������_������_wy1x pk04.wee.png
اما در فایل های انگلیسی مشکلی ندارم بایدچیکار کنم به نظرتون کلی استک اورفلو رو زیر و رو کردم چیزه خاصی گیرم نیومد:گریه:
URL url = new URL(f_url[0]);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
// Set the size of the transfer stream, in case that the application
// collapses due to small memory, this method is used when we don't
// know the size of the content, we use HTTP request without cache
httpURLConnection.setChunkedStreamingMode(128 * 1024);// 128K
// Set the input and output
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setUseCaches(false);
// Set the HTTP method
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
httpURLConnection.setRequestProperty("Charset", "UTF-8");
httpURLConnection.setRequestProperty("Content-Type",
"multipart/form-data;boundary=" + boundary);
// Get outputstream according to the url connection
DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream ());
// Write the HTTP POST header
dos.writeBytes(twoHyphens + boundary + end);
dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\"; filename=\""
+ f_url[1].substring(f_url[1].lastIndexOf("/") + 1)
+ "\"" + end);
dos.writeBytes(end);
FileInputStream fis = new FileInputStream(f_url[1]);
int bufferSize = 8 * 1024; // The size of the buffer, 8KB.
byte[] buffer = new byte[bufferSize];
int length = 0;
while ((length = fis.read(buffer)) != -1) {
// Write data to DataOutputStream
dos.write(buffer, 0, length);
}
dos.writeBytes(end);
dos.writeBytes(twoHyphens + boundary + twoHyphens + end);
fis.close(); // Close the FileInputStream.
dos.flush(); // Flush the data to DataOutputStream.
// Get the content of the response
InputStream is = httpURLConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is, "utf-8");
BufferedReader br = new BufferedReader(isr, 8 * 1024);
result = br.readLine();
Log.d(DBAdapter.TAG, result);
} catch (Exception e) {
e.printStackTrace();
}