I would like to send, from my android app to my backend API an image.
So in my android app I convert an image in base64 string. That part works perfectly.
Android Code:
Bitmap resized = Bitmap.createScaledBitmap(AccueilActivity.photo, 720, 1280, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
resized.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] byteArray = baos.toByteArray();
String encodedImage = new String(""+Base64.encodeBase64URLSafeString(byteArray));
When I want to execute the endpoint https request, it fails !
Campagneendpoint endpoint = endpointBuilder.build();
try {
result=endpoint.sendCampagne(encodedImage).execute();
} catch (IOException e) {
e.printStackTrace();
}
And I've got this error:
javax.net.ssl.SSLException: Write error: ssl=0x78edde30: I/O error during system call, Broken pipe
But If I pass directly the base64 string, It works !
Campagneendpoint endpoint = endpointBuilder.build();
try {
result=endpoint.sendCampagne("_9j_4AAQSkZJRgABAQAAAQABAAD_2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH_2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH_wAARCAUAAtADASIAAhEBAxEB_8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL_8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4-Tl5ufo6erx8vP09fb3-Pn6_8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL_8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMz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_dfvRgr3i2_RwlOdSKjBN6LmaTjFLa8nytRtyQevSTim2pyNnV_iJPZahBbeHYo9QD3BNzLPdyxw3Lq90LcpH5vmhoTMonjX_XxXFypuH3slel_Bv9mnxz8UdctfN0y-tmlaWT7DPb-a0cNtdQygziJ41tp").execute();
} catch (IOException e) {
e.printStackTrace();
}
I tried that but same problem:
String encodedImage = new String(Base64.encodeBase64URLSafeString(byteArray));
String encodedImage = Base64.encodeBase64URLSafeString(byteArray);
Only hard instanciation seems to work :
String encodedImage = "_9j_4AAQSkZJRgABAQAAAQABAAD_2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH_2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH_wAARCAUAAtADASIAAhEBAxEB_8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL_8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4-Tl5ufo6erx8vP09fb3-Pn6_8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL_8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2N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41tp";
For the moment I can't send image to my backend API because there is a bug I don't know where... Anyone had already get this error ?
The problem was I had a heap size overflow, so convert image in base64 was not a good idea..
You can only send messages no longer than 1MB. If you want to store larger files (including images) you should use Blobstore. Here is a good explanation how to use Blobstore for Java with examples.
Then you just store blobKey in your Datastore and serve it from Blobstore using servlets if needed.
Related
I am calling a json API from which I am getting a pdf element , it looks like this , this file is only for example as it is corrupted but looks like this :
JVBERi0xLjUNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIvTGFuZyhlbi1VUykgL1N0cnVjdFRyZWVSbDQTRGRTNBQ0MxQTg5PjwxOTIzMDRGMTgwOTZCMzQ0QjExQ0E0RkUzQUNDMUE4OT5dIC9QcmV2IDk3NjgwL1hSZWZTdG0gOTY0MTg+Pg0Kc3RhcnR4cmVmDQoxMDgzNzgNCiUlRU9G
I want to convert it into pdf to display it into web view in my application.
My tried Code:
String fileUrl = response.getPdf();
byte[] bytes = null;
try {
bytes = fileUrl.getBytes("UTF-8");
Log.e("Byte Array",bytes.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
It Converts into [B#a4d4cef. After this i am not understanding what to do.
Any help would be appreciated.
Thanks.
I have created a camera app where I want to send the frames I receive in onCameraFrame of OpenCV library to server in real-time or say with minimum delay. I was able to achieve map to string conversation in real-time but facing two problems in sending the string to the server.
The string is too large and few Connections like httpUrlConnection in android is not able to send this.
I want to send this big string to the server on one short as quick as possible to achieve the real-time effect.
private Bitmap convertMatToBitMap(Mat input) {
Bitmap bmp = null;
Mat rgb = new Mat();
Imgproc.cvtColor(input, rgb, Imgproc.COLOR_mRGBA2RGBA);
try {
bmp = Bitmap.createBitmap(rgb.cols(), rgb.rows(),Bitmap.Config.ARGB_8888);
Utils.matToBitmap(rgb, bmp);
}
catch (CvException e){
Log.d("Exception",e.getMessage());
}
String bmpStringObj = BitMapToString(bmp);
sendRequest(bmpStringObj); // This is be super fast
return StringToBitMap(bmpStringObj);
}
The above code converts map to bit map and I need to send the string format of this bitmap to server.
Does anyone know how to compress Ti.Utils.base64encode??
for example i have this code :
uploadFile = Ti.Filesystem.getFile(pathFile, listing[_fileCtr].toString());
uploadFileName = listing[_fileCtr].toString();
encodedFile = Ti.Utils.base64encode(uploadFile.read()).toString();
//Send Image to .NET web service
And this is the method in my web services for decompressing image from titanium (if i can compress my image before):
static byte[] Decompress(byte[] input)
{
using (MemoryStream output = new MemoryStream(input))
{
using (GZipStream zip = new GZipStream(output, CompressionMode.Decompress))
{
List<byte> bytes = new List<byte>();
int b = zip.ReadByte();
while (b != -1)
{
bytes.Add((byte)b);
b = zip.ReadByte();
}
return bytes.ToArray();
}
}
Until now, i can't find some method for compressing my byte array so i can decompress them using my .NET method..
If u guys have any information about my problem, please tell me..
Many thanks.. :)
In .Net you can use System.Convert.FromBase64String to converts the specified string, which encodes binary data as base-64 digits, to an equivalent 8-bit unsigned integer array.
System.Convert.FromBase64String(encodedString);
From my android app I am sending an image to C# server converting it to Base64
#Override
public void onPictureTaken(byte[] data, Camera camera)
{
String image = Base64.encodeToString(data, Base64.DEFAULT);
sendtoserver(image);
}
from the server side I received a string but don't know how to convert it and save it.For help I am getting this string tell me how to convert it and save it in C#
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ
Did you try using Convert.FromBase64String(string s) ?
Source: http://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspx
UPDATE (posted here instead of in the comments, since the code would display better)
Your Base64 representation is incorrect. For the image you gave in the comments, the Base64 representation is 339801 characters long.
I used the following code to generate a Base64 representation:
string path = #"C:\1XlqZF2.jpg";
Image img = Image.FromFile(path);
byte[] arr;
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, ImageFormat.Jpeg);
arr = ms.ToArray();
}
String b64 = Convert.ToBase64String(arr);
What is the Base64 class you are using ? I couldn't find it on MSDN.
I have scenario where i need to transfer one or more file depending on situation over the network. The size of the files will be between 700KB and 900KB. After upload completes the server will respond with one number, irrespective of the number of files uploaded.
I have been trying to upload it with ksoap2 library after converting it to Base64, but it failed. It would fail when size of my soap header xml size goes around some where 1048000 or so chars.
Then i decided to change my way of upload and am looking to use either HttpURLConnection or http client.
I cannot decide on which one will be efficient for my scenario.
Thanks
Here is the code
code:
InputStream is = getResources()
.openRawResource(R.raw.file_name);
int size = 0;
// Read the entire resource into a local byte buffer.
byte[] buffer = new byte[1024];
try {
while ((size = is.read(buffer, 0, 1024)) >= 0) {
baos.write(buffer, 0, size);
}
is.close();
buffer = baos.toByteArray();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
base64string = new String(Base64.encode(buffer, Base64.DEFAULT));
error
org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null#1:1 in java.io.InputStreamReader#4101ce48)
at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:2035)
at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:126)
at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
I dont know what kind of server you would like to use.
Your issue of that the files stops while upload might be in your server settings. in your php config for example you can define maximum uploaded file sizes etc.
here a php example:
public void uploadFile(){
try {
FileInputStream fis =this.openFileInput(NAME_OF_FILE);
HttpFileUploader htfu = new HttpFileUploader("http://11.0.6.23/test2.php","noparamshere", NAME_OF_FILE);
htfu.doStart(fis);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Read more: http://getablogger.blogspot.com/2008/01/android-how-to-post-file-to-php-server.html#ixzz27YPjwX8B
EDIT: You could also try to make your soap transfer more efficient by implementing MTOM:
Check out MTOM, a W3C standard designed to transfer binary files through SOAP.
From Wikipedia:
MTOM provides a way to send the binary data in its original binary form,
avoiding any increase in size due to encoding it in text.
Related resources:
SOAP Message Transmission Optimization Mechanism http://www.w3.org/TR/soap12-mtom/
Message Transmission Optimization Mechanism (Wikipedia) http://en.wikipedia.org/wiki/MTOM