7
Tôi gặp sự cố khi tải tệp .doc lên .Net WCF từ ứng dụng Android của tôi. Tôi có thể gửi tập tin nhưng nó không được hỗ trợ trên WCF kết thúc. Đây là phương pháp của tôi để tải lên:Tải tệp MS Word từ Android lên .Net WCF?
protected void checkinmethod(String rid) throws Exception {
File SDCardRoot = Environment.getExternalStorageDirectory();
//create a new file, specifying the path, and the filename
//which we want to save the file as.
File file = new File(SDCardRoot, rid+".doc");
InputStream in = new FileInputStream(file);
byte[] bytearray=new byte[(int) file.length()];
int ab=0;
do
{
ab=in.read(bytearray, 0, bytearray.length);
} while(ab>0);
InputStream mystream= new ByteArrayInputStream(bytearray);
InputStreamEntity se=new InputStreamEntity(mystream, 10000);
HttpPost request = new HttpPost("http://10.66.52.247/tutorwcf/Service.svc/Service/updateMyDoc1");
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/msword");
request.setEntity(se);
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
// Read response data into buffer
char[] buffer = new char[(int)responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
statuss.setText(new String(buffer));
//
}
catch (Exception e) {
// TODO: handle exception
Log.e("hi", "exception is", e);
statuss.setText("exception");
}
}
đây là mã .net:
FileStream fileToupload = new FileStream("D:\\myfile.doc", FileMode.Create, FileAccess.Write);
byte[] bytearray = new byte[10000];
int bytesRead, totalBytesRead = 0;
do
{
bytesRead = mystream.Read(bytearray, 0, bytearray.Length);
totalBytesRead += bytesRead;
} while (bytesRead > 0);
fileToupload.Write(bytearray, 0, bytearray.Length);
fileToupload.Close();
fileToupload.Dispose();
return "success";
}
Xin vui lòng gửi liên kết hoặc mã hoặc bất cứ điều gì.
Nếu bạn không có ý tưởng về vấn đề này xin vui lòng xếp hạng lên câu hỏi này .. nhờ
Vấn đề chính xác là gì? Bạn có nhận được bất kỳ thông báo lỗi hoặc ngoại lệ nào khi bạn chạy mã không? – Kangkan
Thưa bạn, vào cuối wcf, tôi nhận được một tập tin từ. Khi tôi cố gắng mở nó, nó cho tôi thấy lỗi "đọc lỗi". nhưng khi tôi mở nó trong pad lưu ý hoặc từ pad nó cho tôi thấy các biểu tượng như thế này: Ï a Ò Ò Ò,,,,,,,, ° D0 j ~ è3߶Îbãí ~ i> ƒØÍ3¿ \ 'õ? ê/ç [ج ¶Géâ \ Ä! Ý-ÛRk. –
xếp hạng câu hỏi của bạn? – Krishnabhadra