public void testUpload () {
try {
String srcUrl = "/ sdcard /"; / / Path
String fileName = "aa.jpg"; / / filename
FileInputStream fis = new FileInputStream (srcUrl + fileName);
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
byte [] buffer = new byte [1024];
int count = 0;
while ((count = fis.read (buffer))> = 0) {
baos.write (buffer, 0, count);
}
String uploadBuffer = new String (Base64.encode (baos.toByteArray ())); / / perform Base64 encoding
String methodName = "uploadImage";
connectWebService (methodName, fileName, uploadBuffer); / / call the webservice
Log.i ("connectWebService", "start");
fis.close ();
} Catch (Exception e) {
e.printStackTrace ();
}
}
private boolean connectWebService (String methodName, String fileName, String imageBuffer) {
String namespace = "http://134.192.44.105:8080/SSH2/service/IService"; / / namespace, that server must interface Note: suffix did not add wsdl,
.
/ / Server side I am using x-fire to achieve webservice interfaceString url = "http://134.192.44.105:8080/SSH2/service/IService"; / / url
corresponding/ / The following is the calling process, and do not understand, then please see the relevant documents
webserviceSoapObject soapObject = new SoapObject (namespace, methodName);
soapObject.addProperty ("filename", fileName); / / Parameter 1 picture name
soapObject.addProperty ("image", imageBuffer); / / Parameter 2 picture string
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope (
SoapEnvelope.VER10);
envelope.dotNet = false;
envelope.setOutputSoapObject (soapObject);
HttpTransportSE httpTranstation = new HttpTransportSE (url);
try {
httpTranstation.call (namespace, envelope); / / This step memory overflow
Object result = envelope.getResponse ();
Log.i ("connectWebService", result.toString ());
} Catch (Exception e) {
e.printStackTrace ();
}
return false;
}
Reply:
No problem
small picture
But a formal pictures sent around 2M they reported memory overflow. . .
Reply:
Block ah no good way
To be a block of private agreements
Reply:
Is that right? Common practice?
I also saw someone mention before block
Then other methods also upload pictures block it
For example Http
Reply:
Block how to do ah. . . ?
Reply:
The landlord, finally how to solve ah, I have encountered this problem
Reply:
Similarly encountered such a problem, seek solutions
No comments:
Post a Comment