Hi,

I am having difficulties in opening image files for upload with iOS. The 
procedure for upload I will explain here is working correctly when deployed 
on an Android device.

This is the code I use to open the image file, perform resizing if 
necessary and return a byte array for upload:

private byte[] ImageToBinary(String imagePath) throws Exception{
        //leemos los archivos en array de bytes

        
        InputStream is = 
FileSystemStorage.getInstance().openInputStream(imagePath);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Log.p("InputStream " + is.available(), Log.INFO);
        Log.p("path:" + imagePath, Log.INFO);
        EncodedImage ei = EncodedImage.create(is, is.available());
        int w = ei.getWidth();
        int h = ei.getHeight();
        Boolean resize = false;
        Image scaled = ei;
        if (w > 2880)
        {
            w = 2880;resize = true;
        }
        if (h > 2160)
        {
            h = 2160;resize = true;
        }
        if (resize)
        {
            scaled = ei.scaled(w, h);
        }
        
        ImageIO.getImageIO().save(scaled, baos, ImageIO.FORMAT_JPEG, 0.5f);
        return baos.toByteArray();
    }

As said this is working in android devices.

As you can see I managed to output basic log information to further explore 
what's happening:

The content of the log is as follows:

[null] 0:0:33,647 - Codename One revisions: 
7239704baccdfe989a53d64edf70d88d938d0e88

[null] 0:0:33,654 - InputStream 1
[null] 0:0:33,655 - 
path:file:/var/mobile/Containers/Data/Application/9163777A-0F7E-4763-932D-8588BAD8A748/Documents/temp_image_0.jpg
[null] 0:0:33,829 - InputStream 1
[null] 0:0:33,831 - 
path:file:/var/mobile/Containers/Data/Application/9163777A-0F7E-4763-932D-8588BAD8A748/Documents/temp_image_0.jpg
[null] 0:0:34,2 - InputStream 1
[null] 0:0:34,4 - 
path:file:/var/mobile/Containers/Data/Application/9163777A-0F7E-4763-932D-8588BAD8A748/Documents/temp_image_0.jpg
[null] 0:0:34,315 - InputStream 1
[null] 0:0:34,316 - 
path:file:/var/mobile/Containers/Data/Application/9163777A-0F7E-4763-932D-8588BAD8A748/Documents/temp_image_0.jpg
[null] 0:0:34,529 - InputStream 1
[null] 0:0:34,531 - 
path:file:/var/mobile/Containers/Data/Application/9163777A-0F7E-4763-932D-8588BAD8A748/Documents/temp_image_0.jpg

...




Can anybody give me any hints on what I might be doing wrong? As you can 
see the InputStream.available() method returns 1. The code execution 
retries performing this operation up to 10 times before definitively 
failing to execute.

Many thanks for any insights.

Carlos Conti.

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to codenameone-discussions+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/fa07137d-bdca-4104-b20a-34a0ad05f740%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to